7.2 · UIView and CALayer, frame, bounds and center

A UIView is a thin object that handles events and layout, backed by a CALayer that handles drawing. The three geometry properties you use every day, frame, bounds and center, are really layer properties seen through a view.

Mental model. The view decides what happens (touches, layout, delegate calls). The layer decides what you see (pixels, animation). Learn which properties live where.

The view–layer pair

Who owns whom, and what each one is for.

  1. What is the relationship between UIView and CALayer? 7.2.1 · L2
    Every UIView owns exactly one backing layer, created from the view’s layerClass (a plain CALayer by default), and the view is that layer’s delegate. The split…

Geometry

Frame, bounds, center and coordinate conversion.

  1. What is the difference between frame and bounds, and what happens to them under a transform? 7.2.2 · L1
    frame is the view’s rectangle in its superview’s coordinate system: where it sits. bounds is its rectangle in its own coordinate system: the size and the…

More in UIKit