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.

  1. How does convert(_:to:) work with a changed bounds origin or a transform, and how does a scroll view scroll? 9.9.1 · L3
    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:)…
  2. How do CATransform3D, perspective (m34), zPosition and sublayerTransform work, and what happens to frame? 9.9.2 · L5
    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.

  1. How does a layer place its bitmap: contentsGravity, contentsRect, contentsCenter, and how does UIView.contentMode map to them? 9.9.3 · L3
    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