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 show
B. Use1. Create an empty application project without storyboard, to manually implement UIWindow's creation code (which is actually what storyboard does)
1 //Manually create UIWindow and add 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 controller view to the UIWindow add UIView to UIWindow in two common ways:
-(void) Addsubview: (UIView *) view;
The view is added directly to the UIWindow, but the view corresponding Uiviewcontroller is not ignored
@property (Nonatomic,retain) Uiviewcontroller *rootviewcontroller;
Automatically add Rootviewcontroller view to UIWindow, responsible for managing the Rootviewcontroller lifecycle
Common methods
-(void) Makekeywindow;
Make current UIWindow into Keywindow (main window)
-(void) makekeyandvisible; make the current UIWindow Keywindow and show it (1) directly add the controller's view to the UIWindow
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
the relationship between four objects of C.app
Other concepts of D.uiwindow1. main Window A. Get the main window [uiapplication Sharedwindow].keywindow B. You can set the main window by Makekeywindow the main window, and Visual C. A screen can only There is a main window that uses the UIWindow of the last update (last using Makekeywindow or makekeyandvisible) as the main window
D.ios7 only the main window can handle TextField input events before all Windows can be processed
1 //Manually create UIWindow and add to screen 2 Self.window = [[UIWindow alloc] Initwithframe:[[uiscreen Mainscreen] Bounds]];3 Self.window.backgroundColor = [Uicolor graycolor];4 [Self.window makekeyandvisible]; At the moment window is the main window 5 6 //manually defined in the. h file a window2, cannot use temporary variables, otherwise it will be recycled 7 self.window2 = [[UIWindow alloc] Initwithframe:cgrectmake (100, 100, 100, 100)]; 8 self.window2.backgroundColor = [Uicolor redcolor];9 [Self.window2 makekeyandvisible];//This time Window2 is the main window
2. All windows on the screen [uiapplication sharedapplication].windows the list of UIWindow opened in this app so that you can touch any of the UIView objects in the app (the keyboard that normally pops up in the text, In a new UIWindow) [UIApplication Sharedapplication].keywindow is used to receive the UIWindow of the keyboard and the message events of the non-touch class, And only one uiwindow at a time in the program is Keywindow. If a text box inside a UIWindow cannot enter text, it may be because the UIWindow is not Keywindow View.window
Get a UIView uiwindow 3.TextField outgoing Keyboard is a separate window
"Program launches four objects" UIWindow