layoutSubviews何时被调用

It’s important to optimize any UIView layoutSubviews method you create, as it can be frequently called, and has the potential for creating recursion (triggering a setNeedsLayout from layoutSubviews can create a loop that will grossly affect your apps performance). Layout subviews is called once per run loop on any view that has had setNeedsLayout or setNeedsDisplayWithRect: called on it. So in addition to any time you manually call these methods, it can be useful to know when the UI framework calls setNeedsLayout/setNeedsDisplay as this will trigger layoutSubviews.

 

layoutSubviews 在以下情况下会被调用:
1、init 初始化不会触发 layoutSubviews

2、addSubview 会触发 layoutSubviews

3、设置 view 的 Frame 会触发 layoutSubviews,当然前提是 frame 的值 (size) 设置前后发生了变化

4、滚动一个 UIScrollView 会触发 layoutSubviews

5、旋转 Screen 会触发父 UIView 上的layoutSubviews 事件

6、改变一个 UIView size 的时候也会触发父 UIView 上的 layoutSubviews 事件

你可能感兴趣的:(layout)