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

Auto Layout in iOS

Auto Layout in iOS

Introduction to Auto Layout in iOS

Sam Kirchmeier

September 12, 2013
Tweet

More Decks by Sam Kirchmeier

Other Decks in Programming

Transcript

  1. Auto Layout Sam Kirchmeier @skirchmeier Adam May @yammada Friday, September

    27, 13
  2. Friday, September 27, 13

  3. Lineup Auto Layout crash course Ways to use it Demos

    & discussion Friday, September 27, 13
  4. Auto Layout Friday, September 27, 13

  5. Friday, September 27, 13

  6. Alternative to Springs & Struts Friday, September 27, 13

  7. Alternative to Springs & Struts Relationships instead of frames Friday,

    September 27, 13
  8. Alternative to Springs & Struts Relationships instead of frames Layout

    is resolved automatically Friday, September 27, 13
  9. Alternative to Springs & Struts Relationships instead of frames Layout

    is resolved automatically Magic Friday, September 27, 13
  10. Who’s used it? Friday, September 27, 13

  11. Why? Friday, September 27, 13

  12. Friday, September 27, 13

  13. Easy Friday, September 27, 13

  14. Easy Versatile Friday, September 27, 13

  15. Easy Versatile Descriptive Friday, September 27, 13

  16. Easy Versatile Descriptive Localizable Friday, September 27, 13

  17. Springs & Struts Auto Layout Friday, September 27, 13

  18. Springs & Struts Auto Layout Hard-coded Friday, September 27, 13

  19. Springs & Struts Auto Layout Hard-coded Content-driven Friday, September 27,

    13
  20. Springs & Struts Auto Layout Hard-coded Isolated Views Content-driven Friday,

    September 27, 13
  21. Springs & Struts Auto Layout Hard-coded Isolated Views Content-driven Related

    Views Friday, September 27, 13
  22. Springs & Struts Auto Layout Hard-coded Isolated Views autoResizingMask Content-driven

    Related Views Friday, September 27, 13
  23. Springs & Struts Auto Layout Hard-coded Isolated Views autoResizingMask Content-driven

    Related Views Constraints Friday, September 27, 13
  24. Springs & Struts Auto Layout Hard-coded Isolated Views autoResizingMask Familiar

    Content-driven Related Views Constraints Friday, September 27, 13
  25. Springs & Struts Auto Layout Hard-coded Isolated Views autoResizingMask Familiar

    Content-driven Related Views Constraints Scary Friday, September 27, 13
  26. Constraints Friday, September 27, 13

  27. Scary Friday, September 27, 13

  28. Scary Friday, September 27, 13

  29. Scary Friday, September 27, 13

  30. Scary attribute attribute == x multiplier + constant Friday, September

    27, 13
  31. Scary attribute attribute == x multiplier + constant Friday, September

    27, 13
  32. Scary attribute == x multiplier + constant top Friday, September

    27, 13
  33. Scary attribute == x multiplier + constant top Friday, September

    27, 13
  34. Scary attribute == x multiplier + constant top Friday, September

    27, 13
  35. Scary == x multiplier + constant top top Friday, September

    27, 13
  36. Scary == x multiplier + constant top top Friday, September

    27, 13
  37. Scary == x + constant top top 1.0 Friday, September

    27, 13
  38. Scary == + constant top top Friday, September 27, 13

  39. Scary == + top top standard Friday, September 27, 13

  40. Scary == + top top standard Friday, September 27, 13

  41. Scary == + top top standard le! le! == +

    standard Friday, September 27, 13
  42. Scary == + top top standard le! le! == +

    standard Same behavior as Springs & Struts No frame necessary Friday, September 27, 13
  43. Le! Top Baseline Width Center X Right Bottom None Height

    Center Y Friday, September 27, 13
  44. Le! Top Baseline Width Center X Right Bottom None Height

    Center Y Leading Trailing Friday, September 27, 13
  45. Scary Friday, September 27, 13

  46. !"#$ Friday, September 27, 13

  47. Unsatisfiability Friday, September 27, 13

  48. Ambiguity Friday, September 27, 13

  49. Content Hugging Compression Resistance Intrinsic Content Size Friday, September 27,

    13
  50. Priorities Friday, September 27, 13

  51. Ways to use it Interface Builder NSLayoutConstraint Visual Format Language

    Friday, September 27, 13
  52. Interface Builder Friday, September 27, 13

  53. NSLayoutConstraint Friday, September 27, 13

  54. NSLayoutConstraint + (id)constraintWithItem:(id)view1 attribute:(NSLayoutAttribute)attr1 relatedBy:(NSLayoutRelation)relation toItem:(id)view2 attribute:(NSLayoutAttribute)attr2 multiplier:(CGFloat)multiplier constant:(CGFloat)constant; Friday,

    September 27, 13
  55. [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:view2 attribute:NSLayoutAttributeTop multiplier:1.0 constant:20.0]; == x

    1.0 + 20.0 top top Friday, September 27, 13
  56. [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:view2 attribute:NSLayoutAttributeTop multiplier:1.0 constant:20.0]; == x

    1.0 + 20.0 top top Friday, September 27, 13
  57. [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:view2 attribute:NSLayoutAttributeTop multiplier:1.0 constant:20.0]; == x

    1.0 + 20.0 top top Friday, September 27, 13
  58. [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:view2 attribute:NSLayoutAttributeTop multiplier:1.0 constant:20.0]; == x

    1.0 + 20.0 top top Friday, September 27, 13
  59. [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:view2 attribute:NSLayoutAttributeTop multiplier:1.0 constant:20.0]; == x

    1.0 + 20.0 top top Friday, September 27, 13
  60. [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:view2 attribute:NSLayoutAttributeTop multiplier:1.0 constant:20.0]; == x

    1.0 + 20.0 top top Friday, September 27, 13
  61. Visual Format Language Friday, September 27, 13

  62. [label]-[textField] Friday, September 27, 13

  63. |-[label]-| Friday, September 27, 13

  64. V:|-(40)-[logo] Friday, September 27, 13

  65. |-(40)-[logo]-[label]-[textField(>=20)]-| Friday, September 27, 13

  66. [NSLayoutConstraint constraintsWithVisualFormat:@"|-[label]" options:0 metrics:nil views:views]; [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[label]" options:0 metrics:nil views:views];

    Friday, September 27, 13
  67. Demo Localization Friday, September 27, 13

  68. Demo Free Form Editor Friday, September 27, 13

  69. UITextView UIScrollView UIMapView Friday, September 27, 13

  70. UITextView UIScrollView UIMapView Friday, September 27, 13

  71. UIImageView UIView Friday, September 27, 13

  72. Z UIScrollView UIImageView UIScrollView contentSize Friday, September 27, 13

  73. Demo Free Form Editor Friday, September 27, 13

  74. Constraint Stacking Friday, September 27, 13

  75. UITextView UIScrollView UIMapView Image Views Friday, September 27, 13

  76. UIImageView UIImageView UIImageView Friday, September 27, 13

  77. UIImageView UIImageView ? ? Friday, September 27, 13

  78. UIImageView UIImageView UIImageView Friday, September 27, 13

  79. UIImageView UIImageView UIImageView ≥20 ≥20 ≥20 Friday, September 27, 13

  80. UIImageView UIImageView ≥20 ≥20 Friday, September 27, 13

  81. Demo Constraint Stacking Friday, September 27, 13

  82. Interface Builder Quirks Friday, September 27, 13

  83. Friday, September 27, 13

  84. Easy to accidentally delete outlets Friday, September 27, 13

  85. Easy to accidentally delete outlets Does not allow ambiguity Friday,

    September 27, 13
  86. Easy to accidentally delete outlets Does not allow ambiguity Adds

    minimum best constraints Friday, September 27, 13
  87. Easy to accidentally delete outlets Does not allow ambiguity Adds

    minimum best constraints Automatically promotes constraints Friday, September 27, 13
  88. Easy to accidentally delete outlets Does not allow ambiguity Adds

    minimum best constraints Automatically promotes constraints Automatically deletes constraints Friday, September 27, 13
  89. Interface Builder Tips Friday, September 27, 13

  90. Friday, September 27, 13

  91. Friday, September 27, 13

  92. Change to portrait/landscape/freeform Friday, September 27, 13

  93. Change to portrait/landscape/freeform Promote constraints to User Constraints Friday, September

    27, 13
  94. Change to portrait/landscape/freeform Promote constraints to User Constraints Learn to

    expect what IB will do Friday, September 27, 13
  95. Change to portrait/landscape/freeform Promote constraints to User Constraints Learn to

    expect what IB will do Size to fit content Friday, September 27, 13
  96. Change to portrait/landscape/freeform Promote constraints to User Constraints Learn to

    expect what IB will do Size to fit content Wait for Xcode 5 Friday, September 27, 13
  97. Recap Introduced Auto Layout Ways to use it Demos Friday,

    September 27, 13
  98. Discussion https://github.com/livefront/autolayout Sam Kirchmeier @skirchmeier Adam May @yammada Friday, September

    27, 13