Here’s a summary for WWDC 2017, Session 412: Auto Layout Techniques in Interface Builder
https://developer.apple.com/videos/play/wwdc2017/412/

Changing layout at runtime

  • Wrap the view containing its subviews and constraints all set, then set the height of this super view to 0, it gets the affects of hiding the elements;
  • When xxxConstraint.isActive = false/true come in pairs, set isActive = false first to avoid the warning message in console;
  • To add some animation to this duration, use a UIView animation block to wrap layoutIfNeeded() as following:
1
2
3
UIView.animate(withDuration: 0.25) {
self.view.layoutIfNeeded()
}

Tracking touch

  • View position is a result of multiple properties:
    • frame: derived from constraints;
    • transform;
  • Transform is great for temporary changes:
    • transform property offsets from frame;
    • CGAffineTransform = translation + rotation + scale; (Explore later)
    • Reset to CGAffineTransform.identity when done.

Dynamic type

  • Fantastic method to debug dynamic type: Xcode -> Menu -> Accessibility Inspector -> Setting -> Drag&Drop Font Size;
  • Check vertical baseline standard spacing for dynamic type.

Safe Areas Layout Guide

  • A new property in UIView;
  • Available in tvOS;
  • Title safe, unobscured content;
  • iOS storyboards:
    • Constraints automatically upgrade;
    • Backwards deployable;
  • LargeTitle support since iOS 11.0.
1
2
3
4
if #available(iOS 11.0, *) {
navigationController?.navigationBar.prefersLargeTitles = true
vc.navigationItem.largeTitleDisplayMode = .always
}

Portional positioning

  • Using spacer view is an nice option when needed in Interface Builder;
    • Mark as hidden;
  • Use UILayoutGuide programmatically.

Stack view adaptive layout

  • From Xcode 9, hidden property can vary by size class.