App entry: main
//set UIApplication object and delegation
int main() {
return UIApplicationMain(xx, xx, UIApplication, AppDelegate);
}
Procedure
- Create UIApplication object
- Create APPDelegate object, and be the UIApplication delegation. it will listen the app life cycle and process memory warning
- Begin a main event loop, keep the app receiving and processing events
- Load info.plist
- if use main.storyboard
- create UIWindow
- load main main.storyboard, and set the initial controller as the rootController
- set window.makeKeyAndVisible()
- show the window
UIWindow
- fun: provide drawing support for the screen UIWindow. That is a special UIView container. every UIView showing into screen is the child View of UIWindow.
why need UIViewController ? instead of UIWindow
- we want rotation function
- see stackOverFlow
Key Window
- fun: a UIWindow can receive keyboard and non-touch event.
- Only one UIWindow is the key window in the given time.
The key window is the one that is designated to receive keyboard and other ooo-touch related events.
Only one window at a time may be the key window.
custom setting UIWindow
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// create window and frame
self.window = UIWindow(frame: UIScreen.main.bounds)
// create rootController
let rootVC = SubwayListerViewController(withTestFile: nil)
let rootNav = UINavigationController(rootViewController: rootVC)
// if setting window and rootController, as default rootController's view will be added into window
// setting rootController, as default, we have rotation function
window?.rootViewController = rootNav
self.window?.makeKeyAndVisible()
return true
}
Window level realtionship
self.window.windowlebel = UIWindowAlert or UIWIndowNormal or UIWindowStatusBar