从百度上搜索了一下layoutSubviews的用处,如下是搜索的结果,固然,笔者是会一一验证的.ide
一、 init初始化不会触发layoutSubviews布局
二、 addSubview会触发layoutSubviewsthis
三、 设置view的Frame会触发layoutSubviews,固然前提是frame的值设置先后发生了变化spa
四、 滚动一个UIScrollView会触发layoutSubviewsorm
五、 旋转Screen会触发父UIView上的layoutSubviews事件事件
六、 改变一个UIView大小的时候也会触发父UIView上的layoutSubviews事件ci
在开始验证以前,先看看layoutSubviews究竟是啥来着:)it
Lays out subviews.io
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.form
在iOS5.1或以前的版本中,这个方法什么也没干.这个方法的默认实现是 用参数来设定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.
若是你须要更加精确的布局,能够在子类里面重写这个方法.仅仅在如下状况下:自动布局达不到你想要效果时你才有必要重写这个方法.你能够直接设置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.
你不能直接调用这个方法.若是你须要强制layout刷新,调用setNeedsLayout来代替.若是你想要当即刷新你的view,调用layoutIfNeeded
大概总结如下就是:
你不要直接调用方法layoutSubviews,若是想要刷新,请调用 setNeedsLayout 或者layoutIfNeeded
1. 一个view是不可以本身调用layoutSubviews,若是要调用,须要调用setNeedsLayout或者 layoutIfNeeded
2. 若是view的frame值为0,即便被添加了耶不会调用layoutSubviews
3. 若是一个view的frame值改变了,那么它的父类的layoutSubviews也会被执行