UIQWindow defines a window object to manage views. A software can only have one window. The main function of window is to provide display for the view and send events to the view. To change the content displayed by the software, you can change the root view of the window.
The screen attribute of UIWindow specifies the display attributes of the window, including bounds, mode, and brightness.
Window configurications are used to listen for changes to the window and screen, including:
UIWindowDidBecomeVisibleNotification
UIWindowDidBecomeHiddenNotification
UIWindowDidBecomeKeyNotification
UIWindowDidResignKeyNotification UIWindow inherits from UIView. This may be a logical obstacle. How can I inherit the canvas from the frame? Do not go too far to the tip of the horn. Isn't the frame in the same shape as the canvas? Take a canvas and use some methods to strengthen it. Can it be used as a frame? This is why a view can be directly added to another view. An application can have only one frame.
Take a look at the system initialization process (in application didfinishlauchingwitexceptions ):
-(BOOL) application :( UIApplication *) application willfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {
UIWindow * window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen] bounds];
MyViewController = [[MyViewController alloc] init];
Window. rootViewController = myViewController;
[Window makeKeyAndVisible];
Return YES;
}
Create an external display:
-(Void) checkForExistingScreenAndInitializeIfPresent
{
If ([[UIScreen screens] count]> 1)
{
// Get the screen object that represents the external display.
UIScreen * secondScreen = [[UIScreen screens] objectAtIndex: 1];
// Get the screen's bounds so that you can create a window of the correct size.
CGRect screenBounds = secondScreen. bounds;
Self. secondWindow = [[UIWindow alloc] initWithFrame: screenBounds];
Self. secondWindow. screen = secondScreen;
// Set up initial content to display...
// Show the window.
Self. secondWindow. hidden = NO;
}
}
-(Void) setUpScreenConnectionNotificationHandlers
{
Nsicationicationcenter * center = [NSNotificationCenter defacenter center];
[Center addObserver: self selector: @ selector (handleScreenDidConnectNotification :)
Name: UIScreenDidConnectNotification object: nil];
[Center addObserver: self selector: @ selector (handleScreenDidDisconnectNotification :)
Name: UIScreenDidDisconnectNotification object: nil];
}
-(Void) handleScreenDidConnectNotification :( NSNotification *) aNotification
{
UIScreen * newScreen = [aNotification object];
CGRect screenBounds = newScreen. bounds;
If (! Self. secondWindow)
{
Self. secondWindow = [[UIWindow alloc] initWithFrame: screenBounds];
Self. secondWindow. screen = newScreen;
// Set the initial UI for the window.
}
}
-(Void) handleScreenDidDisconnectNotification :( NSNotification *) aNotification
{
If (self. secondWindow)
{
// Hide and then delete the window.
Self. secondWindow. hidden = YES;
Self. secondWindow = nil;
}
}