We know UIWindow inherit from UIView, so uiwindow in addition to have all the functions of uiview, there are some unique property methods, the most common is that the program just started, call UIWindow makekeyandvisible make the whole program visible.
-(BOOL) Application: (uiapplication *) application didfinishlaunchingwithoptions: ( Nsdictionary *) launchoptions {
//Override point for customization after application launch.
self. window = [[UIWindowalloc]initwithframe: [uiscreen Mainscreen]. bounds ];
Viewcontroller = [[viewcontrolleralloc]init];
self. Window. Rootviewcontroller =Viewcontroller;
[self. window makekeyandvisible];
return YES;
}
So the main role of UIWindow:
1, as the top-level container for UIView, contains all the UIView required for the application display.
2. Delivering touch messages and keyboard events to UIView
Let's talk about a property that is closely related to this blog windowlevel
Uikit_extern Const Uiwindowlevel Uiwindowlevelnormal;
Uikit_extern Const Uiwindowlevel Uiwindowlevelalert;
Uikit_extern Const Uiwindowlevel Uiwindowlevelstatusbar;
Where the value of Uiwindowlevelnormal makes 0, the value of Uiwindowlevelalert is $, and the value ofUiwindowlevelstatusbar is
Let's start with the features we're going to implement today
The so-called password protection, is in the app into the background, re-enter the app when you need to enter a password access to the app password can be inconsistent with the user's login password, to protect the user's personal information, to prevent the user's phone is not around when people peek, or mobile phone lost, The leakage of sensitive information, such as the mining of wealth, there is such a function, so generally involving money, sensitive personal information of the app should have such a function
First, customize a UIWindow subclass
@interface Passwordinputwindow:UIWindow
+ (passwordinputwindow *) sharedinstance;
-(void) show;
@end
where + (passwordinputwindow *) sharedinstance; is a way to create a singleton
The specific implementation is as follows:
+ (passwordinputwindow *) sharedinstance
{
Static ID sharedinstance =nil;
Static dispatch_once_t Oncetoken;
dispatch_once (&oncetoken, ^{
Sharedinstance = [[selfalloc]initwithframe: [uiscreenmainscreen]. Bounds];
});
return sharedinstance;
}
-(void) show
{
self. Windowlevel =Uiwindowlevelalert;//top level display
[self Makekeywindow];
Self. Hidden =NO;
}
The specific demo implementation is as follows;
Demo
iOS UIWindow Magic (a) App password protection function