Autolayout之 关于+requiresConstraintBasedLayout方法作用
来源:互联网 发布:彩票app源码 编辑:程序博客网 时间:2024/06/08 03:34
看到很多Autolayout写的自定义控件中都实现了+requiresConstraintBasedLayout方法,一直不知道这个方法有什么用,因为不实现这个方法也没发现有什么影响。经过查找资料,有解释如下:
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
0 0
- Autolayout之 关于+requiresConstraintBasedLayout方法作用
- requiresConstraintBasedLayout <iOS>
- iOS学习之AutoLayout常用方法
- iOS开发:AutoLayout关于更新的几个方法
- 108.UIView关于布局和约束的方法(AutoLayout)
- AutoLayout之关于苹果原生约束的探索
- 关于hashCode方法的作用
- 关于hashCode方法的作用
- 关于hashCode方法的作用
- 关于hashCode方法的作用
- 关于hashCode方法的作用
- 关于hashCode方法的作用
- 关于hashCode方法的作用
- 关于HashCode()方法的作用
- 关于hashCode方法的作用
- 关于hashCode方法的作用
- 关于hashCode方法的作用
- 关于hashCode方法的作用
- spring MVC +Spring + Hibernate + PostgreSQL框架的集成和多租户( 一)
- linux 下 iozone随机读写测试报错: error reading block
- IOS开发—通过ChildViewController实现view的切换
- sort b
- UVA 11983-Weird Advertisement-k次以上覆盖矩形面积(线段树+扫描线)
- Autolayout之 关于+requiresConstraintBasedLayout方法作用
- 【leetcode】172. Factorial Trailing Zeroes
- LeetCode 40 Combination Sum II
- Robot Framework自动化测试框架(三):Android自动化
- Recording HTTP traffic on iOS devices with HP LoadRunner
- 如何将pdf转换成word格式可编辑的格式
- android原生与js的交互。
- IOS5中的addChildViewController
- OC语言笔记(二):OC字符串操作