UIWindow & UIWindowLevel笔记
2015-09-21 17:48
411 查看
一片枫叶
追求卓越,成功就会在不经意间追上你跟随自己的节奏学习,思考,总结,找到自己,别人才会找到你
下一篇:基于NSBundle的工程结构
UIWindowLevel详解
UIWindow & UIWindowLevel笔记一、UIWindow是一种特殊的UIView,通常在一个程序中只会有一个UIWindow,但可以手动创建多个UIWindow,同时加到程序里面。UIWindow在程序中主要起到三个作用:
1、作为容器,包含app所要显示的所有视图
2、传递触摸消息到程序中view和其他对象
3、与UIViewController协同工作,方便完成设备方向旋转的支持
二、通常我们可以采取两种方法将view添加到UIWindow中:
1、addSubview
直接将view通过addSubview方式添加到window中,程序负责维护view的生命周期以及刷新,但是并不会为去理会view对应的ViewController,因此采用这种方法将view添加到window以后,我们还要保持view对应的ViewController的有效性,不能过早释放。
2、rootViewController
rootViewController时UIWindow的一个遍历方法,通过设置该属性为要添加view对应的ViewController,UIWindow将会自动将其view添加到当前window中,同时负责ViewController和view的生命周期的维护,防止其过早释放
三、WindowLevel
UIWindow在显示的时候会根据UIWindowLevel进行排序的,即Level高的将排在所有Level比他低的层级的前面。下面我们来看UIWindowLevel的定义:
const UIWindowLevel UIWindowLevelNormal; const UIWindowLevel UIWindowLevelAlert; const UIWindowLevel UIWindowLevelStatusBar; typedef CGFloat UIWindowLevel;
IOS系统中定义了三个window层级,其中每一个层级又可以分好多子层级(从UIWindow的头文件中可以看到成员变量CGFloat _windowSublevel;),不过系统并没有把则个属性开出来。UIWindow的默认级别是UIWindowLevelNormal,我们打印输出这三个level的值分别如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor yellowColor];
self.window.rootViewController = [[ViewController alloc]init];
[self.window makeKeyAndVisible];
CGRect windowRect = CGRectMake(50, 50, [UIScreen mainScreen].bounds.size.width - 100, [UIScreen mainScreen].bounds.size.height - 100);
UIWindow *normalWindow = [[UIWindow alloc]initWithFrame:windowRect];
normalWindow.backgroundColor = [UIColor blueColor];
normalWindow.windowLevel = UIWindowLevelNormal;
normalWindow.rootViewController = [[NormalViewController alloc]init];
[normalWindow makeKeyAndVisible];
UIWindow *alertWindow = [[UIWindow alloc]initWithFrame:CGRectMake(70, 70, [UIScreen mainScreen].bounds.size.width - 140, [UIScreen mainScreen].bounds.size.height - 140)];
alertWindow.windowLevel = UIWindowLevelAlert;
alertWindow.backgroundColor = [UIColor redColor];
alertWindow.rootViewController = [[AlertViewController alloc]init];
[alertWindow makeKeyAndVisible];
UIWindow *statusWindow = [[UIWindow alloc]initWithFrame:CGRectMake(10, 80, [UIScreen mainScreen].bounds.size.width - 20, 30)];
statusWindow.backgroundColor = [UIColor greenColor];
statusWindow.windowLevel = UIWindowLevelStatusBar;
statusWindow.rootViewController = [[StatusViewController alloc]init];
[statusWindow makeKeyAndVisible];
return YES;
}
前提是必须将arc关闭,否则执行完毕会把所有的自定义window释放掉。
相关文章推荐
- 励精图治---Concurrency---GUI设计
- UItableView一些小方法
- poj3581 Sequence(后缀数组sa的运用+离散化)
- ThreadPoolExecutor使用和思考-线程池大小设置与BlockingQueue的三种实现区别
- Opencv3.0+opencv_contrib_lib +VS2013(编译)+CMake-gui(最近的版本都可以)
- 判断 Fragment 的 UI 是否可见
- UML建模之时序图(Sequence Diagram)
- 【UIFramework】前端UI框架—导航条
- java中queue的使用
- requestWindowFeature()的应用
- android NotificationCompat.Builder 使用
- 15.Android 异步更新UI 技巧
- DBCP针对不同数据库的validationQuery
- 递归-快速排序quickSort
- 字符串 intValue、floatValue、doubleValue、longLongValue 方法可以正确转换的位数或者大小
- iOS经典讲解之UICollectionView
- A new session could not be created. (Original error: Requested a new session but one was in progress) )错误解决办法
- POJ 2533 Longest Ordered Subsequence (DP动态规划)
- PAT研究生入学考试2015.03第四题Build A Binary Search Tree (30) 题解
- List<data> 数据转为easyui-datagrid json数据格式