IOS 值得注意的地方
2015-07-29 12:50
483 查看
- (void)loadView
{
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
UIView *contentView = [[UIView alloc] initWithFrame:applicationFrame];
contentView.backgroundColor = [UIColor blackColor];
self.view = contentView;
levelView = [[LevelView alloc] initWithFrame:applicationFrame viewController:self];
[self.view addSubview:levelView];
}
上述代码首先得到屏幕的frame,然后根据该frame生成了一个contentView,并指定当前ViewController的root view为contentView,然后生成了一个LevelView的自定义View并将它通过addSubview:方法添加到当前ViewController当中,完成view的初始化加载。
关于loadView方法的重写,官方文档中有一个明显的注释,原文如下:
Note: When
overriding the
you should not call
view-loading behavior and usually just wastes CPU cycles. Your own implementation of the
should do all the work that is needed to create a root view and subviews for your view controller.
意思是当通过代码方式去创建你自己的view时,在loadView方法中不应该调用super,如果调用[super loadView]会影响CPU性能。
2.
1,如果是从代码层面开始使用Autolayout,需要对使用的View的translatesAutoresizingMaskIntoConstraints的属性设置为NO.
即可开始通过代码添加Constraint,否则View还是会按照以往的autoresizingMask进行计算.
而在Interface Builder中勾选了Ues
Autolayout,IB生成的控件的translatesAutoresizingMaskIntoConstraints属性都会被默认设置NO.
{
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
UIView *contentView = [[UIView alloc] initWithFrame:applicationFrame];
contentView.backgroundColor = [UIColor blackColor];
self.view = contentView;
levelView = [[LevelView alloc] initWithFrame:applicationFrame viewController:self];
[self.view addSubview:levelView];
}
上述代码首先得到屏幕的frame,然后根据该frame生成了一个contentView,并指定当前ViewController的root view为contentView,然后生成了一个LevelView的自定义View并将它通过addSubview:方法添加到当前ViewController当中,完成view的初始化加载。
关于loadView方法的重写,官方文档中有一个明显的注释,原文如下:
Note: When
overriding the
loadViewmethod to create your views programmatically,
you should not call
super. Doing so initiates the default
view-loading behavior and usually just wastes CPU cycles. Your own implementation of the
loadViewmethod
should do all the work that is needed to create a root view and subviews for your view controller.
意思是当通过代码方式去创建你自己的view时,在loadView方法中不应该调用super,如果调用[super loadView]会影响CPU性能。
2.
1,如果是从代码层面开始使用Autolayout,需要对使用的View的translatesAutoresizingMaskIntoConstraints的属性设置为NO.
即可开始通过代码添加Constraint,否则View还是会按照以往的autoresizingMask进行计算.
而在Interface Builder中勾选了Ues
Autolayout,IB生成的控件的translatesAutoresizingMaskIntoConstraints属性都会被默认设置NO.
相关文章推荐
- iOS HTML图片本地预览
- ios 获取屏幕的属性和宽度
- iOS开发多线程篇—多线程简单介绍
- 防止在iOS设备中的Safari将数字识别为电话号码
- iOS手动内存管理
- iOS中锁的应用
- IOS CoreText
- ios的一种简单的模糊效果
- iOS字符串和可变字符串
- 百度地图iOS SDK开发教程(珍藏版)
- ios 使用GCD 多线程 教程
- iOS 手势识别器概述
- iOS各版本图标尺寸汇总
- 使用PhoneGap打包HTML成iOS应用
- IOS 整体框架类图值得收藏
- ios文件预览以及使用其他应用打开文件
- 申请苹果加急审核
- 9秒学院教你如何成为iOS开发达人
- iOS-动画的两种方式
- iOS开发之各种动画各种页面切面效果