Autolayout之 关于+requiresConstraintBasedLayout方法作用
2016-05-16 15:13
381 查看
看到很多Autolayout写的自定义控件中都实现了+requiresConstraintBasedLayout方法,一直不知道这个方法有什么用,因为不实现这个方法也没发现有什么影响。经过查找资料,有解释如下:
意思就是基于约束的布局是懒触发的,只有在添加了约束的情况下,系统才会自动调用 -updateConstraints 方法,如果把所有的约束放在 updateConstraints中,那么系统将会不知道你的布局方式是基于约束的,所以 重写+requiresConstraintBasedLayout 返回YES就是明确告诉系统:虽然我之前没有添加约束,但我确实是基于约束的布局!这样可以保证系统一定会调用 -updateConstraints 方法 从而正确添加约束.
文章分享:
constraint-based layout engages lazily when someone tries to use it (e.g., adds a constraint to a view). If you do all of your constraint set up in -updateConstraints, you might never even receive updateConstraints if no one makes a constraint. To fix this chicken and egg problem, override this method to return YES if your view needs the window to use constraint-based layout.
意思就是基于约束的布局是懒触发的,只有在添加了约束的情况下,系统才会自动调用 -updateConstraints 方法,如果把所有的约束放在 updateConstraints中,那么系统将会不知道你的布局方式是基于约束的,所以 重写+requiresConstraintBasedLayout 返回YES就是明确告诉系统:虽然我之前没有添加约束,但我确实是基于约束的布局!这样可以保证系统一定会调用 -updateConstraints 方法 从而正确添加约束.
文章分享:
http://www.starming.com/index.php?v=index&view=81
相关文章推荐
- easy ui datagrid 获取选中行的数据
- IOS UITableView编辑模式中,只有移动功能
- iOS开发-UITextView中return 点击事件的监听方法
- iOS开发-UI中懒加载的使用方法
- String、StringBuilder和StringBuffer的区别和应用场景
- IOS UITableView 改变编辑模式下的移动图标
- 使用javafx scenebuilde 添加controller 提示错误invalid
- [Android] 异步消息处理机制(Handler 、 Looper 、MessageQueue)源码解析
- STORM StateQuery方法的使用与底层原理
- 解决“Dynamic Web Module 3.0 requires Java 1.6 or newer.”错误
- 自定义标签TLD文件中,rtexprvalue属性是什么意思
- iOS触摸手势——UITouch
- UI自动化
- 《UNIX环境高级编程》第二版:Apue.h文件引入
- L2-005. 集合相似度 unique的应用 去重 vector
- iOS触摸手势知识介绍(UITouch & UIGestureRecognizer)
- IOS开发中UIFont字体设置
- leetcode.187. Repeated DNA Sequences
- iOS 如何让UITableView显示时自动滚动到底部(不闪动)
- UGUI研究院之SpritePacker打包参数(四)