layoutSubviews几时被调用

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.

 

1、frame有变化会调用

2、addSubview会调用过

3、旋转screen会调用

4、滚动一个UIScrollView会调用

5、子view大小有变化时,supreview也会调用