1、一篇比较通俗易懂的文章
2、官方文档
✨layoutSubviews - UIView | Apple Developer Documentation
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.
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.
You should not call this method directly. If you want to force a layout update, call the set<wbr style="box-sizing: inherit;">Needs<wbr style="box-sizing: inherit;">Layout
method instead to do so prior to the next drawing update. If you want to update the layout of your views immediately, call the layout<wbr style="box-sizing: inherit;">If<wbr style="box-sizing: inherit;">Needed
method.
什么情况会调用:
1.直接调用[self setNeedsLayout];(这个在上面苹果官方文档里有说明)
2.addSubview的时候。
3.当view的size发生改变的时候。
4.滑动UIScrollView的时候。
5.旋转Screen会触发父UIView上的layoutSubviews事件。
网友评论