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.
- What is the relationship between UIView and CALayer?
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.
- What is the difference between frame and bounds, and what happens to them under a transform?
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
- 7.1 · Hit testing, the responder chain and gesture recognisers
- 7.3 · View controller lifecycle, containment, presentation and transitions
- 7.4 · Navigation, tab, split and page controllers
- 7.5 · Compositional layout, diffable data sources, cell reuse and prefetching
- 7.6 · UITableView, still asked and still everywhere
- 7.7 · Trait collections, size classes, safe area, keyboard and appearance
- 7.8 · Keyboard shortcuts, pointer, Apple Pencil and multitasking
- 7.9 · Hosting SwiftUI in UIKit and UIKit in SwiftUI
- 7.10 · Initialisers, stack views, scroll views and modern buttons
- 7.11 · Layout passes, retain cycles and menus
- 7.12 · Refreshing diffable cells, outlines and carousel layouts
- 7.13 · View-tree exercises and long navigation stacks