iOS开发iOS DeveloperiOS学习笔记

约束布局之旅—2

2017-05-29  本文已影响45人  osbornZ

Layout相关

AutoLayout生效时,ViewController在干什么?

  1. 任何原因引起View的尺寸被改变
  2. 调用ViewController的“viewWillLayoutSubviews”方法
  3. 未启用Autolayout情况,调用“layoutSubviews”
  4. 启用Autolayout情况,调用ViewController的"updateViewConstraints"方法。在这个方法里,会调用所有subview的“updateConstraints”方法。
  5. 当界面被刷新后,调用ViewController的“viewDidLayoutSubviews”。(这时候获取到的 UIView 的Frame 就是界面显示的 Size)

Constraint

Constraints must be added after adding views to their superviews. All constraints need to be in the same hierarchy. If they aren’t, the app will immediately crash.

In viewDidLoad() setupFrame with setupConstraints();一般的子view约束布局建议加在 viewDidLoad 中;

上一篇 下一篇

猜你喜欢

热点阅读