9.1 · Auto Layout, intrinsic size, and when layoutSubviews and draw run

Auto Layout turns relationships between views into frames. Most layout bugs are a missing relationship (ambiguity), two relationships that disagree (a conflict), or a pass that runs at the wrong time.

Mental model. You do not set positions, you state rules, and a solver finds the frames. Layout (where things go) and drawing (what they look like) are separate passes with separate triggers.

The constraint system

Constraints, priorities, intrinsic size, hugging and compression.

  1. How does Auto Layout work, and what are intrinsic size, content hugging, compression resistance, priorities and ambiguity? 9.1.1 · L2
    Auto Layout is a constraint solver (a Cassowary-style linear-equation system). Each constraint is a rule of the form item1.attribute = multiplier ×…

Layout and display passes

What triggers <code>layoutSubviews</code> and <code>draw(_:)</code>.

  1. What is the difference between layoutSubviews and draw(_:), and what triggers each? 9.1.2 · L3
    Layout and display are two independent passes. layoutSubviews() sets the geometry of a view’s subviews. It is triggered when the view is resized, when subviews…

More in Layout, rendering & animation