1.觸發(fā)LayoutSubviews的幾種情況
(1)init初始化的時(shí)候不會(huì)觸發(fā)LayoutSubviews,view刷新不用LayoutSubviews方法诸典,也沒有這個(gè)方法
(2)addSubview時(shí)候會(huì)觸發(fā)LayoutSubviews,前提是frame不是0
(3)設(shè)置view的frame會(huì)觸發(fā)LayoutSubviews描函,前提是設(shè)置前后view的frame發(fā)生變化
(4)旋轉(zhuǎn)Screen會(huì)觸發(fā)父UIView上的LayoutSubviews
(5)改變一個(gè)UIView的大小的時(shí)候會(huì)觸發(fā)父UIView的LayoutSubviews
2.LayoutSubviews的官方解釋
Lays out subviews.
The default implementation of this method does nothing on iOS 5.1 and earlier. Otherwise, the default implementation uses any constraints you have set to determine the size and position of any subviews.
在iOS5.1或之前的版本中,這個(gè)方法什么也沒干.這個(gè)方法的默認(rèn)實(shí)現(xiàn)是用參數(shù)來設(shè)定subviews的尺寸和位置的.
Subclasses can override this method as needed to perform more precise layout of their subviews. You should override this method only if the autoresizing and constraint-based behaviors of the subviews do not offer the behavior you want. You can use your implementation to set the frame rectangles of your subviews directly.
如果你需要更加精確的布局,可以在子類里面重寫這個(gè)方法.僅僅在以下情況下:自動(dòng)布局達(dá)不到你想要效果時(shí)你才有必要重寫這個(gè)方法.你可以直接設(shè)置subviews的尺寸.
You should not call this method directly. If you want to force a layout update, call the 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 layoutIfNeeded method.
你不能直接調(diào)用這個(gè)方法.如果你需要強(qiáng)制layout刷新,調(diào)用setNeedsLayout來代替.如果你想要立即刷新你的view,調(diào)用layoutIfNeeded