80 likes | 258 Views
Mikhail Merkulov @ mikhailmerkulov. AUTO LAYOUT BASICS. The problem. The problem with springs and struts Traditional solutions Hard-coded layout 2+ nibs Auto layout What about iPhone 5?. Auto layout concept. Constraint-based layout Frames are determined automatically
E N D
Mikhail Merkulov @mikhailmerkulov AUTO LAYOUT BASICS
The problem • The problem with springs and struts • Traditional solutions • Hard-coded layout • 2+ nibs • Auto layout • What about iPhone 5?
Auto layout concept • Constraint-based layout • Frames are determined automatically • attribute1 == multipler × attribute2 + constant • Button.left = superview.left + 10 • New class: NSLayoutConstraint • Immutable except Constant property • Demo
How to code auto layout? • Low level API • The visual format language • Demo
Runtime problems • The constraints must be sufficient • Ambiguous layout • The constrains must not conflict • Unsatisfiable constraints • Unexpected ways • Demo
Migrating to auto layout • Partial and full conversion? • Convert nibs • Review programmatically created views • Replace setFrame, etc. • Rethink your layout (Divide responsibility between controllers and views) • Add constraints • updateConstraints and intrinsicContentSize
References • Cocoa Auto Layout Guide • Session 202: Introduction to Auto Layout for iOS and OS X • Session 228: Best Practices for Mastering Auto Layout • Session 232: Auto Layout by Example • Beginning Auto Layout in iOS 6