iOS Development UIWindow

Source: Internet
Author: User

1 , overview

UIWindow is a special kind of UIView , usually in a app there will only be one UIWindow .

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 also says that without UIWindow, you can't see any UI interface.

2 , add UIView to the UIWindow the two common ways in which

Way One:

-(void) Addsubview: (UIView *) view;

The view is added directly to the UIWindow, but the view corresponding Uiviewcontroller is not ignored

For example:

Mjoneviewcontroller *one = [[Mjoneviewcontroller alloc] init];

[Self.window AddSubview:one.view];

Mode II (the method of actual use in development, preferred ):

@property (Nonatomic,retain) Uiviewcontroller *rootviewcontroller;

Automatically add Rootviewcontroller view to UIWindow, responsible for managing the Rootviewcontroller lifecycle

For example:

Mjoneviewcontroller *one = [[Mjoneviewcontroller alloc] init];

Self.window.rootViewController = one;

Common methods:

-(void) Makekeywindow;

Make the current UIWindow into Keywindow (main window).

-(void) makekeyandvisible;

Make the current UIWindow into Keywindow and show it.

3 , Get UIWindow

[UIApplication sharedapplication].windows

A list of UIWindow that opens in this app so you can touch any of the UIView objects in your app.

(usually input text pop-up keyboard, in a new UIWindow)

[UIApplication Sharedapplication].keywindow

The UIWindow used to receive message events for keyboards and non-touch classes, and only one uiwindow per time in a 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 the UIWindow where a uiview is located.

"Remarks" in an empty project, appdelegate class adheres to the uiapplicationdelegate protocol, and then at the time of the corresponding event uiapplication will notify it. Delegate object, for example, when the app starts to complete uiapplication will notify appdelegate , which is then automatically called appdelegate in the didfinishlaunchingwithoptions , when the direct start of a black interface, there is no anything. To display something, first use the set method to add a UIWindow to it:

Self.window =

[[UIWindow Alloc]initwithframe[uiscreen mainscreen].bounds];

added cannot be displayed because there may be multiple UIWindow , we want to invoke Get method to get the settings that were just set UIWindow set it as the main window and display it:

[Self.window makekeyandvisible];

That's what it shows. UIWindow , we can go to this later. UIWindow Add the controller (equivalent to Android in the Activity ) to be added as the root controller for the controller to be displayed:

Self.window.rootViewController =

Myviewcontroller;

iOS Development UIWindow

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.