LayoutSubviews总结
2015-11-22 19:38
363 查看
layoutSubviews的官方文档描述:
1)the default implementation of this method does nothing on iOS5.1 and earlier, Otherwise, the default implementation uses any constraints you have set to determine the size and position of any subview.
subclasses can override this method as needed to perform more precise layout of your subviews. you should override this method only if the autoresizing and constraints-based behavior of the subviews do not offer the behavior you want. you can use your implementation to set the frame rectangle of your subviews directly.
you should not call this method directly, if you want to force a layout update, call setNeedsLayout method instead to do so prior to the next drawing update. if you want to update the layout of your views immediately, call the layoutIfNeed method.
2)called to notify the viewController that its view is about to layout its subviews.
When a view bounds change, the view adjust the position of its subviews. your view controller can override this method to make changes before the view layout its subviews. the default of this method does nothing.
从官方文档里找了三个重点:
1)layoutsubviews dose nothing:ios 5.1之前默认的layoutsubview是什么都不做的。
2)iOS 5.1之后,layoutsubviews把设置的constraints翻译成frame,实现autolayout
3)在layoutSubviews方法中可以做一些custome的事情,来调整View hierarchy的结构样式,如:在ViewDidLoad中,self.view的frame可能是不准确的,这时候需要在layoutSubviews中设置一下frame。
1)the default implementation of this method does nothing on iOS5.1 and earlier, Otherwise, the default implementation uses any constraints you have set to determine the size and position of any subview.
subclasses can override this method as needed to perform more precise layout of your subviews. you should override this method only if the autoresizing and constraints-based behavior of the subviews do not offer the behavior you want. you can use your implementation to set the frame rectangle of your subviews directly.
you should not call this method directly, if you want to force a layout update, call setNeedsLayout method instead to do so prior to the next drawing update. if you want to update the layout of your views immediately, call the layoutIfNeed method.
2)called to notify the viewController that its view is about to layout its subviews.
When a view bounds change, the view adjust the position of its subviews. your view controller can override this method to make changes before the view layout its subviews. the default of this method does nothing.
从官方文档里找了三个重点:
1)layoutsubviews dose nothing:ios 5.1之前默认的layoutsubview是什么都不做的。
2)iOS 5.1之后,layoutsubviews把设置的constraints翻译成frame,实现autolayout
3)在layoutSubviews方法中可以做一些custome的事情,来调整View hierarchy的结构样式,如:在ViewDidLoad中,self.view的frame可能是不准确的,这时候需要在layoutSubviews中设置一下frame。
相关文章推荐
- ListView控件详解
- 编译安装thrift和使用autoconf,automake生成Makefile文件
- 不只是给面试加分 -- Java WeakReference的理解与使用
- 1012. 数字分类 (20)
- 本周心得
- int和Integer有什么区别?
- poj-2140-Herd Sums- 数学规律-连续和为N的方案数
- EL获取list长度!并判断
- docker常用命令
- webview操作方法
- 富文本之某些字体之间的间距特殊调整
- 已分类图如何获取混淆矩阵以及变化方向检测 confusion matrix change detection
- 关于XCode7objc语法增强
- 哈希表
- 软件工程第三次作业
- Java有没有goto?
- NYOJ 79 拦截导弹(LIS)
- 《leetCode》:Add Binary
- short s1 = 1; s1 = s1 + 1;有错吗?short s1 = 1; s1 += 1;有错吗?
- float f=3.4;是否正确?