//UIWindow图层上添加控件
//例如添加蒙版 也可添加到self.navigationController.view 图层上或者self.tabBarController.view 图层上
//self.view < self.navigationController.view < self.tabBarController.view < UIWindow
/*
UIWindow:一般作为UIView的容器
应用场景:
当需要将某些控件显示到最上层时就可以创建一个window,然后将空间添加到window上
支付宝、记账类软件 认证界面(手势解锁)大部分都是用UIWindow做的
注意:
1.一般情况下不要随意创建window,不要滥用,因为只要创建就会自动添加到界面上(不用addsubview),那么如果滥用window会导致应用程序的层级结构混乱
2.window是有级别的,级别越高就显示在越顶层(键盘级别最高)
默认有3个级别:UIWindowLevelNormal(0.0) < UIWindowLevelAlert(1000.0) < UIWindowLevelStatusBar(2000.0)
也可自定义window.windowLevel = 4000.0;
UIWindow特点:
只要创建就会自动添加到界面上
系统弹出UIAlertView、弹出键盘、来短信、来电、电量不足等也是用的UIWindow
如果需要window监听点击事件需要设置frame,因为window创建后没有frame
UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
//移除window 可在点击方法里直接 window = nil;
*/
//cover为frame是[UIScreen mainScreen].bounds的半透明或透明色button
UIWindow *window = [UIApplication sharedApplication].keyWindow;
[window addSubview:cover];