A.uiwindow Concept1. Inheriting the UIView is a special kind of UIView2. Usually an app has only one Uiwindow3.ios program started, and the first view created is UIWindow4. No UIWindow, nothing to showB. Use1. Create an empty application project without storyboard, to manually implement UIWindow's creation code (which is actually what storyboard does)
1 // manually create the UIWindow and add it to screen 2 Self.window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]]; 3 Self.window.backgroundColor = [Uicolor whitecolor]; 4 [Self.window makekeyandvisible];
2. Create a controller 3. Add the view of the controller to the UIWindow (1) To add the controller's view to UIWindow directly
1 // Add Controller 2 Viewcontroller *controller = [[Viewcontroller alloc] init]; 3 [Self.window AddSubview:controller.view];
This method is not recommended becauseA. It is possible that after the custom controller variable is destroyed, its view is also used in the UIWindow, and if the controller is used again it causes a crash B. Various related events (such as screen rotation) cannot be handled due to the absence of a custom controller to UIWindow (2) Set the custom controller to UIWindow Rootviewcontroller set the root controller, will automatically add the view of the custom controller to UIWindow
1 // Add Controller 2 Viewcontroller *controller = [[Viewcontroller alloc] init]; 3 // [Self.window AddSubview:controller.view]; 4 Self.window.rootViewController = Controller;
(3) Setting the status bar visible in controller
1 - (BOOL) Prefersstatusbarhidden {2 return NO; 3 }
4. Interface switch is actually different controller replace to UIWindow above change Self.window.rootViewController
[iOS base Control-6.10.7] UIWindow & Program startup process