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.
- How does Auto Layout work, and what are intrinsic size, content hugging, compression resistance, priorities and ambiguity?
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>.
- What is the difference between layoutSubviews and draw(_:), and what triggers each?
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
- 9.2 · From layout to the GPU, and the two layer trees
- 9.3 · Offscreen passes, rasterization, blending, shadows and masks
- 9.4 · Implicit and explicit animation, UIView animation, and animators
- 9.5 · Core Graphics, UIBezierPath and draw(_:)
- 9.6 · TextKit 1 and 2, and Text in SwiftUI
- 9.7 · Frame budgets, ProMotion, hitches and hangs
- 9.8 · Margins, stack views, guides, constraint ownership, the layout cycle and measuring
- 9.9 · Coordinate conversion, 3D transforms and layer contents
- 9.10 · How UIView animation really works, springs, timing and display links
- 9.11 · Transform order, fill rules, text measurement, text containers and bitmaps
- 9.12 · Rectangle containment and moving a point between coordinate spaces