作用:Layout 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.
调用总结:
- view层级变化:
1) addSubview: view和subview都触发;2) removeFromSuperview: superView触发;3) bringToFront/sendToBack: 如果subView层级发生变化,view将触发layoutSubviews,如:[_v0 bringSubviewToFront:_v1]; //_v0触发layoutSubviews复制代码
- bounds变化:
view的bounds(width || height)发生变化,view及其superView触发layoutSubviews;eg. _v0上放_v1, _v1的bounds变化将引起_v0和_1的layoutSubviews复制代码
- layoutIfNeeded会立刻执行layoutSubviews(如有);
- setNeedsLayout会强制在下一次runloop调用(Invalidates the current layout of the receiver and triggers a layout update during the next update cycle.)。