Do you really know uiwindow?

Source: Internet
Author: User
Tags file info

One: First look at the definition of UIWindow

Ns_class_available_ios (2_0) @interface Uiwindow:uiview//window screen, default is [UIScreen mainscreen], cannot change, otherwise no interface@property (nonatomic,strong) UIScreen *Screen Ns_available_ios (3_2); //window's view level, default is 0.0@property (nonatomic) Uiwindowlevel windowlevel; //whether it is Keywindow@property (Nonatomic,ReadOnly, getter=Iskeywindow) BOOL Keywindow;//This method should not be called manually and will be called automatically when window becomes Keywindow to notify window. You can inherit UIWindow override this method to implement functionality- (void) Becomekeywindow; //the method should not be called manually, and when window is no longer keywindow (for example, another window instance calls the-Makekeywindow or-makekeyandvisible method) It is automatically called to notify the window.                          You can inherit UIWindow override this method to implement functionality. - (void) Resignkeywindow; //This method changes the window to Keywindow, but does not affect the display state- (void) Makekeywindow;//The main window is displayed and the window is set to key and displayed, which makes the window display and becomes Keywindow. Calling this method causes the window to be ranked at the top of its level group. If you only want to change the display of the window without affecting the Keywindow state, you can set the window's hidden property to no directly. - (void) makekeyandvisible; //Root Controller@property (Nullable, Nonatomic,strong) Uiviewcontroller *Rootviewcontroller Ns_available_ios (4_0);//uiapplication calls the window's method to distribute events to the window, which then distributes the event to the appropriate target, such as distributing the touch event to a truly touch view. You can call this method directly to distribute custom events. - (void) Sendevent: (Uievent *)Event; //converts a coordinate in the window to a coordinate value when it is in the target window-(Cgpoint) Convertpoint: (cgpoint) point Towindow: (Nullable UIWindow *) window; //converts a coordinate in the target window to the coordinate value in the window-(Cgpoint) Convertpoint: (cgpoint) point Fromwindow: (Nullable UIWindow *) window; //converts a matrix in the window to a matrix value when it is in the target window-(CGRect) Convertrect: (cgrect) Rect Towindow: (Nullable UIWindow *) window;//converts a matrix in the target window to the matrix value when it is in the window-(CGRect) Convertrect: (cgrect) Rect Fromwindow: (Nullable UIWindow *) window; @end

uiwindow is a special uiview, usually in a app at least one uiwindow. ios after the program is started, the first view control created is uiwindow, then the view of the controller is created, and finally the controller's view added to uiwindow, the controller view is displayed on the screen. A ios program can be displayed on the screen entirely because it has uiwindow, that is to say, there is no uiwindow will not see any Span class= "S1" >ui interface. The status bar and keyboard are special uiwindow;uiwindow or an important part of event handling, when an application initially receives an event, it is sent to the appropriate uiwindow object, which is then passed to the appropriate uiview object. At the same time, window and view Controller objects work together can also achieve interface rotation and other control operations.

Knowledge point 1 :uiwindowlevel constant Value sets the UIWindow level

Const // By default, the value is 0 Const //  const//  value is

This property represents the windowOn screen ZPosition on the axis, the system provides the Uiwindowlevel Always than calling the keyboard Window Level big 1, select the copy of the input, paste and other options in the window Window Window at low level< Span class= "S1" to the top of Window

knowledge point 2: Monitoring notifications for window:

 uikit_extern nsstring *//  uikit_extern nsstring *const  uiwindowdidbecomehiddennotification; //      Uikit_extern nsstring *const  uiwindowdidbecomekeynotification; //      Uikit_extern nsstring *const  uiwindowdidresignkeynotification; //  
is returned.

Knowledge points 3: code to create window initialization Interface

-(BOOL) Application: (UIApplication *) application willfinishlaunchingwithoptions: (nsdictionary *) launchOptions {     *window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]];     = [[Myviewcontroller alloc] init];     = Myviewcontroller;    [Window makekeyandvisible];     return YES;}

Knowledge point 4: How is UIWindow created in a project with storyboard?

When the user clicks on the application icon, first executes the main function, executes Uiapplicationmain (), creates the application according to its third and fourth parameters, creates the proxy, and set the proxy to application (see the project configuration file Info.plist inside the storyboard name, according to this name to find the corresponding storyboard), open an event loop, when the program is loaded, he will call the agent Didfinishlaunchi Ngwithoptions: Method. Before calling the Didfinishlaunchingwithoptions: method, the storyboard is loaded, a window is created at the time of loading, the controller that the arrow points to is created, the controller is set to UIWindow's root controller, The window is then displayed, which shows the interface after the run.

tell me something. 5 : get UIWindow

1:[uiapplication sharedapplication].windows Opens a list of UIWindow in this app so you can touch any UIView object in your app ( The keyboard that usually enters text pops up in a new UIWindow ).

2:[uiapplication Sharedapplication].keywindow(Gets the application's main window) is used to receive UIWindow for keyboard and non-touch class message Events, And only one uiwindow at a time in the program is Keywindow.

Tip: If a text box inside a UIWindow cannot enter text, it may be because the UIWindow is not Keywindow.

3: View.window get The UIWindow of a uiview.

Do you really know 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.