Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Auto-Layout.pdf

6af08fba5b3a50a06c7f1bf980458590?s=47 Shuai Liu
September 22, 2015

 Auto-Layout.pdf

6af08fba5b3a50a06c7f1bf980458590?s=128

Shuai Liu

September 22, 2015
Tweet

More Decks by Shuai Liu

Other Decks in Technology

Transcript

  1. Auto Layout

  2. Frame + autoresizingMask Auto Layout

  3. basis • SuperView的位置确定了,那么SubView的位置就可 以被确定 • SuperView -> SubView的{x, y, width,

    height} -> SubView的位置
  4. Cassowary You provide rules, whether through IB or through code,

    and the Auto Layout system transforms those rules into view frames.
  5. Constraint y = kx + b view1的某个属性 = k ×

    view2的某个属性 + b
  6. NSLayoutConstraint + (instancetype)constraintWithItem:(id)view1 attribute:(NSLayoutAtribute)attr1 relatedBy:(NSLayoutRelation)relation toItem:(id)view2 attribute:(NSLayoutAttribute)attr2 multiplier:(CGFloat)multipler constant:(CGFloat)c

  7. 开始Auto Layout • No frame & autoresizingMask • ⽗父View当前的⼤大⼩小是不可靠的

  8. None
  9. 思路 • 合理的把⼦子View分组 • 确定⼤大致依赖关系 —— 要想确定A的位置,⾸首先我得知道B 的位置 & 只要B的位置定下来了,那么A的位置就可以被确定

    • 找出那些只依赖⽗父View的View(⼀一定存在),先 添加他们的约束 • 根据依赖关系,⼀一级⼀一级的添加约束
  10. None
  11. None
  12. None
  13. Code

  14. Advanced • Content Hugging & Compression Resistance • Intrinsic Content

    Size • Animation