您的位置:首页 > 其它

LayoutSubviews总结

2015-11-22 19:38 363 查看
layoutSubviews的官方文档描述:

1)the default implementation of this method does nothing on iOS5.1 and earlier, Otherwise, the default implementation uses any constraints you have set to determine the size and position of any subview.

subclasses can override this method as needed to perform more precise layout of your subviews. you should override this method only if the autoresizing and constraints-based behavior of the subviews do not offer the behavior you want. you can use your implementation to set the frame rectangle of your subviews directly.

you should not call this method directly, if you want to force a layout update, call 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 layoutIfNeed method.

2)called to notify the viewController that its view is about to layout its subviews.

When a view bounds change, the view adjust the position of its subviews. your view controller can override this method to make changes before the view layout its subviews. the default of this method does nothing.

从官方文档里找了三个重点:

1)layoutsubviews dose nothing:ios 5.1之前默认的layoutsubview是什么都不做的。

2)iOS 5.1之后,layoutsubviews把设置的constraints翻译成frame,实现autolayout

3)在layoutSubviews方法中可以做一些custome的事情,来调整View hierarchy的结构样式,如:在ViewDidLoad中,self.view的frame可能是不准确的,这时候需要在layoutSubviews中设置一下frame。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: