IOS UIKit: UIWindow

Source: Internet
Author: User

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;
 
}
 
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.