IOS UIWindow and Windowlevel Learning

Source: Internet
Author: User

Several key points of pop

  1. Keywindow : " The key window is the one, that's designated to receive keyboard and other Non-touch related events. only one window at a time can be the key window will show the main object in the front
  2. The makekeyandvisible method makes the object window a keywindow but if Keywindow 's windowlevel Less than other windowlevel the current Keywindow is not in the top-most priority display
  3. UIWindow has three levels, namely Normal,statusbar,alert. The values for these three levels are 0,1000,2000 from left to right.
  4. Depending on the principle of UIWindow display level precedence, (UIWindow will be sorted according to Uiwindowlevel when displayed) that is, the "always" row Windowlevel is shown in front of his lower level.
  5. The system default keywindow windowlevel is normal , then the first to display the created Windowlevel must be greater than or equal to normal will show up on the top.
  6. Create UIWindow do not add to any of the controls above, directly created is automatically added to the UIWindow on the Create how to show destruction and general UIVIEW There's a difference in the way you see code comments

:

See Code:

////HFWINDOWVIEWCONTROLLER.M//Sectiondemo////Created by HF on 2017/5/25.//Copyright 2017 Hf-liqun. All rights reserved.//#import "HFWindowViewController.h"@interfaceHfwindowviewcontroller ()//Creating Properties@property (nonatomic, strong) UIWindow *MyWindow1;@end@implementationHfwindowviewcontroller- (void) viewdidload {[Super viewdidload]; //Create a Test buttonUIButton *tempbtn =[UIButton Buttonwithtype:uibuttontypesystem]; Tempbtn.frame= CGRectMake ( the, -, Self.view.frame.size.width- the*2, -); [Tempbtn settitle:@"dot I create a window"Forstate:uicontrolstatenormal]; //generate different windowlevel levels of Windows with button click events[tempbtn addtarget:self Action: @selector (CLICKBTN:) forcontrolevents:uicontroleventtouchupinside]; [Self.view addsubview:tempbtn];}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}#pragmamark-event-(void) Clickbtn: (ID) sender{[self test1];}- (void) Clickwindowbtn: (ID) sender{//Window DestructionSelf.myWindow1.hidden = YES;//The UI effect is optionalSelf.mywindow1 = nil;//This method is really to remove UIWindow}#pragmaMark-private/** * * 1, create window does not add to any of the controls above, directly created is automatically added to the window * 2, create a window than the default window windowlevel large windows to see what effect, The effect is to cover the original window.*/- (void) test1{//Create Window    if(Self.mywindow1 = =Nil) {        if(IOS9) {//>=ios9 self.mywindow1= [UIWindowNew];//The size of the window is later defaulted}Else{Self.mywindow1= [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds];//on which version of the system, there is nothing wrong with it .} UIButton*WINDOWBTN =[UIButton Buttonwithtype:uibuttontypecustom]; [Windowbtn settitle:@"dot I destroy the yellow window"Forstate:uicontrolstatenormal]; Windowbtn.backgroundcolor=[Uicolor Redcolor]; Windowbtn.frame= CGRectMake ( the, -, Self.view.frame.size.width- the*2, -);        [Windowbtn addtarget:self Action: @selector (CLICKWINDOWBTN:) forcontrolevents:uicontroleventtouchupinside];            [Self.mywindow1 ADDSUBVIEW:WINDOWBTN]; }    //sets the window's color, which is set to yellow, to easily view the window's hierarchical relationshipSelf.myWindow1.backgroundColor =[Uicolor Yellowcolor]; //set the windowlevel of the windowSelf.myWindow1.windowLevel = Uiwindowlevelstatusbar;//Todo:normal,statusbar,alert can modify the impact of the experience level change on the display window, respectively, for 0,1000,2000.Self.myWindow1.hidden =NO; [Self.mywindow1 makekeyandvisible];//Become a Keywindow}@end

IOS UIWindow and Windowlevel Learning

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.