iOS / 关于layoutSubviews方法

2020-02-01  本文已影响0人  不不不不同学

1、一篇比较通俗易懂的文章

iOS 谈谈layoutSubviews何用 - 简书

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事件。

上一篇下一篇

猜你喜欢

热点阅读