9.9 · Coordinate conversion, 3D transforms and layer contents
Layers are rectangles with a coordinate system, a transform and a bitmap. Most visual surprises are one of those three misread.
Mental model. Every layer has its own coordinate space; conversion applies bounds origin and transform for you, and contents is just a bitmap placed by gravity.
Spaces and 3D
Moving points between coordinate systems, and perspective.
- How does convert(_:to:) work with a changed bounds origin or a transform, and how does a scroll view scroll?
Each view’s frame is expressed in its superview’s coordinates, and its subviews are placed in its own bounds coordinates. convert(_:to:) and convert(_:from:)… - How do CATransform3D, perspective (m34), zPosition and sublayerTransform work, and what happens to frame?
A layer’s transform is a 4×4 matrix (CATransform3D) applied around its anchor point, so a rotation about the y-axis flips a card over. Without perspective the…
Contents
How a layer’s bitmap is placed and stretched.
- How does a layer place its bitmap: contentsGravity, contentsRect, contentsCenter, and how does UIView.contentMode map to them?
A layer’s contents is a bitmap (a CGImage, or what draw(_:) produced). contentsGravity decides how it fits the bounds, and UIView.contentMode is a thin layer…
More in Layout, rendering & animation
- 9.1 · Auto Layout, intrinsic size, and when layoutSubviews and draw run
- 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.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