CALayer: frame property
The frame property is the layer's position and size in the superlayer's coordinate system.
Value
A CGRect, in pt. x and y are the coordinates of the layer's top-left corner; the y axis points down.
- Readable and writable.
- Defaults to
(0, 0, 0, 0). A layer created withnewisn't visible until you setframe. - When writing, you can give a
CGRector{ x, y, width, height }. TheCGRectyou read is read-only; to change it, assign a new value. - Changing
framealso changes the size ofboundsandposition. - A sublayer's
framedoesn't follow the size of its superview; see Sublayer sizes don't follow the view. - For a view's own layer (
view.layer), useview.frameor constraints rather than writinglayer.frame: the next layout pass overwrites it with the result computed from constraints. This is not verified in the simulator. framecan't be animated; usepositionfor movement animations.
Invalid values
TypeError
The value isn't an object, or is missing fields, or a field isn't a finite number.
Examples
js
const layer = new CALayer();
layer.frame = new CGRect(1, 2, 3, 4);
console.log(String(layer.position));Result: The console prints CGPoint(2.5, 4): the center is at (2.5, 4).
Corresponding iOS API
CALayer.frame. CGRectMake(1, 2, 3, 4) is written new CGRect(1, 2, 3, 4).