UIWindow is a special kind of uiview that usually has only one uiwindow in an app.
After the iOS program starts, the first view control created is UIWindow, then the controller's view is created, the controller's view is added to the UIWindow, and the controller's view is displayed on the screen.
An iOS program can be displayed on the screen entirely because it has uiwindow. It says that without UIWindow, you can't see any UI interface.
How to get UIWindow
(1) [UIApplication sharedapplication].windows the UIWindow list 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)
(2) [UIApplication Sharedapplication].keywindow (Get the application's main window) is used to receive keyboard and non-touch class message Event UIWindow, And only one uiwindow at a time in the program is Keywindow.
Note: Code verification, non-Keywindow can also accept keyboard messages
Tip: If a text box inside a UIWindow cannot enter text, it may be because this uiwindow is not Keywindow
(3) View.window get the UIWindow of a UIView
Uiwindowlevel
We know that UIWindow has three levels, namely normal, StatusBar, Alert. Output their three levels of values, we found 0,1000,2000 from left to right, that is, the normal level is the lowest, StatusBar is intermediate and the alert level is highest. And usually our program interface is at the normal level, the system at the top of the status bar should be at the statusbar level, Uiactionsheet and uialertview these are usually used to interrupt the normal process, remind users and other operations, It is therefore located at the alert level.
According to the window display level priority principle, the high level will be displayed in the top level, lower levels below, our program normal display view at the bottom;
Keywindow
This is explained in the official documentation, "The key window is the one, and the designated to receive keyboard and other Non-touch related events. Single Window at a time can be the key window. "Keywindow is the specified message to receive keyboard and non-touch classes, and only one window per moment in the program is Keywindow.
Observing UIWindow's documentation, we can see that there are four notifications about window changes:
Uiwindowdidbecomevisiblenotification
Uiwindowdidbecomehiddennotification
Uiwindowdidbecomekeynotification
Uiwindowdidresignkeynotification
The object in these four notification objects represents a Window object that is currently displayed (hidden) and becomes Keywindow (non-Keywindow), where the userinfo is empty. So we can register this four message, and then print the information to see the changes in the Keywindow and the window display, hidden changes
The process of becoming a keywindow is like this.
1. The default window of the program is displayed first
2. The default window becomes Keywindow
The window of 3.AlertView is displayed.
4. The default window becomes Keywindow
5. The final Alertview window becomes Keywindow
Overall is "want to be the boss (Keywindow), first from the younger brother (not Keywindow) Start mixing " and according to the test we can also know that the default window level is 0, that is, the normal class The level of the Alertview window is 1996, a little bit lower than alert.
Keywindow changes and window display are the same as above, and we can see that the level of the Actionsheet window is 2001;
When we click Actionsheet Cancel, we will see the process
1. First the Actionsheet window becomes non-Keywindow
2. The Program default window becomes Keywindow
3.ActionSheet window is hidden
---------------------------------------------------------------------------
@property (nonatomic,readonly) Nsarray *windows; with Keywindow
At first, I thought it was strange, not to say that an app has only one window? Why also get the number group, the results of a test only know after the loss, in addition to window and Uitexteffetswindow. Online Keywindow refers to the currently active window, the window that interacts with the user . Windows is a window in which the current app opens, such as a keyboard in a window, andalert in a window. In the Windows array, thewindow is arranged according to Windowlevel, and the last one is overlaid on top. The Windows array here does not include a system-provided window, such as a status bar in a window created by a system.
Note: Keywindow are not immutable, and when you create Alertview or actionsheet, the window they are in will become Keywindow. In other words, the default window created by the system becomes Keywindow first, and when the frame is alertview, the window becomes Keywindow, and the default Keywindow becomes non-keywindow.
IOS knowledge about UIWindow