<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.5.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "QuartzCore",
  "identifier" : "/documentation/QuartzCore/CALayer",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Animation"
    ],
    "preciseIdentifier" : "c:objc(cs)CALayer"
  },
  "title" : "CALayer"
}
-->

# CALayer

An object that manages image-based content and allows you to perform animations on that content.

```
class CALayer
```

## Overview

Layers are often used to provide the backing store for views but can also be used without a view to display content. A layer’s main job is to manage the visual content that you provide but the layer itself has visual attributes that can be set, such as a background color, border, and shadow. In addition to managing visual content, the layer also maintains information about the geometry of its content (such as its position, size, and transform) that is used to present that content onscreen. Modifying the properties of the layer is how you initiate animations on the layer’s content or geometry. A layer object encapsulates the duration and pacing of a layer and its animations by adopting the [`CAMediaTiming`](/documentation/QuartzCore/CAMediaTiming) protocol, which defines the layer’s timing information.

If the layer object was created by a view, the view typically assigns itself as the layer’s delegate automatically, and you should not change that relationship. For layers you create yourself, you can assign a [`delegate`](/documentation/QuartzCore/CALayer/delegate) object and use that object to provide the contents of the layer dynamically and perform other tasks. A layer may also have a layout manager object (assigned to the [`layoutManager`](/documentation/QuartzCore/CALayer/layoutManager) property) to manage the layout of subviews separately.

## Topics

### Creating a layer

[`layer`](/documentation/QuartzCore/CALayer/layer)

Creates and returns an instance of the layer object.

[`init()`](/documentation/QuartzCore/CALayer/init())

Returns an initialized `CALayer` object.

[`init(layer:)`](/documentation/QuartzCore/CALayer/init(layer:))

Override to copy or initialize custom fields of the specified layer.

[`init(remoteClientId:)`](/documentation/QuartzCore/CALayer/init(remoteClientId:))

Initializes a layer with a remote client ID.

### Accessing related layer objects

[`presentation()`](/documentation/QuartzCore/CALayer/presentation())

Returns a copy of the presentation layer object that represents the state of the layer as it currently appears onscreen.

[`model()`](/documentation/QuartzCore/CALayer/model())

Returns the model layer object associated with the receiver, if any.

### Accessing the delegate

[`delegate`](/documentation/QuartzCore/CALayer/delegate)

The layer’s delegate object.

### Providing the layer’s content

[`contents`](/documentation/QuartzCore/CALayer/contents)

An object that provides the contents of the layer. Animatable.

[`contentsRect`](/documentation/QuartzCore/CALayer/contentsRect)

The rectangle, in the unit coordinate space, that defines the portion of the layer’s contents that should be used. Animatable.

[`contentsCenter`](/documentation/QuartzCore/CALayer/contentsCenter)

The rectangle that defines how the layer contents are scaled if the layer’s contents are resized. Animatable.

[`display()`](/documentation/QuartzCore/CALayer/display())

Reloads the content of this layer.

[`draw(in:)`](/documentation/QuartzCore/CALayer/draw(in:))

Draws the layer’s content using the specified graphics context.

### Modifying the layer’s appearance

[`contentsGravity`](/documentation/QuartzCore/CALayer/contentsGravity)

A constant that specifies how the layer’s contents are positioned or scaled within its bounds.

[Contents Gravity Values](/documentation/QuartzCore/contents-gravity-values)

The contents gravity constants specify the position of the content object when the layer bounds is larger than the bounds of the content object. They are used by the [`contentsGravity`](/documentation/QuartzCore/CALayer/contentsGravity) property.

[`opacity`](/documentation/QuartzCore/CALayer/opacity)

The opacity of the receiver. Animatable.

[`isHidden`](/documentation/QuartzCore/CALayer/isHidden)

A Boolean indicating whether the layer is displayed. Animatable.

[`masksToBounds`](/documentation/QuartzCore/CALayer/masksToBounds)

A Boolean indicating whether sublayers are clipped to the layer’s bounds. Animatable.

[`mask`](/documentation/QuartzCore/CALayer/mask)

An optional layer whose alpha channel is used to mask the layer’s content.

[`isDoubleSided`](/documentation/QuartzCore/CALayer/isDoubleSided)

A Boolean indicating whether the layer displays its content when facing away from the viewer. Animatable.

[`cornerRadius`](/documentation/QuartzCore/CALayer/cornerRadius)

The radius to use when drawing rounded corners for the layer’s background. Animatable.

[`maskedCorners`](/documentation/QuartzCore/CALayer/maskedCorners)

[`CACornerMask`](/documentation/QuartzCore/CACornerMask)

[`borderWidth`](/documentation/QuartzCore/CALayer/borderWidth)

The width of the layer’s border. Animatable.

[`borderColor`](/documentation/QuartzCore/CALayer/borderColor)

The color of the layer’s border. Animatable.

[`backgroundColor`](/documentation/QuartzCore/CALayer/backgroundColor)

The background color of the receiver. Animatable.

[`shadowOpacity`](/documentation/QuartzCore/CALayer/shadowOpacity)

The opacity of the layer’s shadow. Animatable.

[`shadowRadius`](/documentation/QuartzCore/CALayer/shadowRadius)

The blur radius (in points) used to render the layer’s shadow. Animatable.

[`shadowOffset`](/documentation/QuartzCore/CALayer/shadowOffset)

The offset (in points) of the layer’s shadow. Animatable.

[`shadowColor`](/documentation/QuartzCore/CALayer/shadowColor)

The color of the layer’s shadow. Animatable.

[`shadowPath`](/documentation/QuartzCore/CALayer/shadowPath)

The shape of the layer’s shadow. Animatable.

[`style`](/documentation/QuartzCore/CALayer/style)

An optional dictionary used to store property values that aren’t explicitly defined by the layer.

[`allowsEdgeAntialiasing`](/documentation/QuartzCore/CALayer/allowsEdgeAntialiasing)

A Boolean indicating whether the layer is allowed to perform edge antialiasing.

[`allowsGroupOpacity`](/documentation/QuartzCore/CALayer/allowsGroupOpacity)

A Boolean indicating whether the layer is allowed to composite itself as a group separate from its parent.

### Layer filters

[`filters`](/documentation/QuartzCore/CALayer/filters)

An array of Core Image filters to apply to the contents of the layer and its sublayers. Animatable.

[`compositingFilter`](/documentation/QuartzCore/CALayer/compositingFilter)

A CoreImage filter used to composite the layer and the content behind it. Animatable.

[`backgroundFilters`](/documentation/QuartzCore/CALayer/backgroundFilters)

An array of Core Image filters to apply to the content immediately behind the layer. Animatable.

[`minificationFilter`](/documentation/QuartzCore/CALayer/minificationFilter)

The filter used when reducing the size of the content.

[`minificationFilterBias`](/documentation/QuartzCore/CALayer/minificationFilterBias)

The bias factor used by the minification filter to determine the levels of detail.

[`magnificationFilter`](/documentation/QuartzCore/CALayer/magnificationFilter)

The filter used when increasing the size of the content.

### Configuring the layer’s rendering behavior

[`isOpaque`](/documentation/QuartzCore/CALayer/isOpaque)

A Boolean value indicating whether the layer contains completely opaque content.

[`edgeAntialiasingMask`](/documentation/QuartzCore/CALayer/edgeAntialiasingMask)

A bitmask defining how the edges of the receiver are rasterized.

[`contentsAreFlipped()`](/documentation/QuartzCore/CALayer/contentsAreFlipped())

Returns a Boolean indicating whether the layer content is implicitly flipped when rendered.

[`isGeometryFlipped`](/documentation/QuartzCore/CALayer/isGeometryFlipped)

A Boolean that indicates whether the geometry of the layer and its sublayers is flipped vertically.

[`drawsAsynchronously`](/documentation/QuartzCore/CALayer/drawsAsynchronously)

A Boolean indicating whether drawing commands are deferred and processed asynchronously in a background thread.

[`shouldRasterize`](/documentation/QuartzCore/CALayer/shouldRasterize)

A Boolean that indicates whether the layer is rendered as a bitmap before compositing. Animatable

[`rasterizationScale`](/documentation/QuartzCore/CALayer/rasterizationScale)

The scale at which to rasterize content, relative to the coordinate space of the layer. Animatable

[`contentsFormat`](/documentation/QuartzCore/CALayer/contentsFormat)

A hint for the desired storage format of the layer contents.

[`render(in:)`](/documentation/QuartzCore/CALayer/render(in:))

Renders the layer and its sublayers into the specified context.

### Modifying the layer geometry

[`frame`](/documentation/QuartzCore/CALayer/frame)

The layer’s frame rectangle.

[`bounds`](/documentation/QuartzCore/CALayer/bounds)

The layer’s bounds rectangle. Animatable.

[`position`](/documentation/QuartzCore/CALayer/position)

The layer’s position in its superlayer’s coordinate space. Animatable.

[`zPosition`](/documentation/QuartzCore/CALayer/zPosition)

The layer’s position on the z axis. Animatable.

[`anchorPointZ`](/documentation/QuartzCore/CALayer/anchorPointZ)

The anchor point for the layer’s position along the z axis. Animatable.

[`anchorPoint`](/documentation/QuartzCore/CALayer/anchorPoint)

Defines the anchor point of the layer’s bounds rectangle. Animatable.

[`contentsScale`](/documentation/QuartzCore/CALayer/contentsScale)

The scale factor applied to the layer.

### Managing the layer’s transform

[`transform`](/documentation/QuartzCore/CALayer/transform)

The transform applied to the layer’s contents. Animatable.

[`sublayerTransform`](/documentation/QuartzCore/CALayer/sublayerTransform)

Specifies the transform to apply to sublayers when rendering. Animatable.

[`affineTransform()`](/documentation/QuartzCore/CALayer/affineTransform())

Returns an affine version of the layer’s transform.

[`setAffineTransform(_:)`](/documentation/QuartzCore/CALayer/setAffineTransform(_:))

Sets the layer’s transform to the specified affine transform.

### Managing the layer hierarchy

[`sublayers`](/documentation/QuartzCore/CALayer/sublayers)

An array containing the layer’s sublayers.

[`superlayer`](/documentation/QuartzCore/CALayer/superlayer)

The superlayer of the layer.

[`addSublayer(_:)`](/documentation/QuartzCore/CALayer/addSublayer(_:))

Appends the layer to the layer’s list of sublayers.

[`removeFromSuperlayer()`](/documentation/QuartzCore/CALayer/removeFromSuperlayer())

Detaches the layer from its parent layer.

[`insertSublayer(_:at:)`](/documentation/QuartzCore/CALayer/insertSublayer(_:at:))

Inserts the specified layer into the receiver’s list of sublayers at the specified index.

[`insertSublayer(_:below:)`](/documentation/QuartzCore/CALayer/insertSublayer(_:below:))

Inserts the specified sublayer below a different sublayer that already belongs to the receiver.

[`insertSublayer(_:above:)`](/documentation/QuartzCore/CALayer/insertSublayer(_:above:))

Inserts the specified sublayer above a different sublayer that already belongs to the receiver.

[`replaceSublayer(_:with:)`](/documentation/QuartzCore/CALayer/replaceSublayer(_:with:))

Replaces the specified sublayer with a different layer object.

### Updating layer display

[`setNeedsDisplay()`](/documentation/QuartzCore/CALayer/setNeedsDisplay())

Marks the layer’s contents as needing to be updated.

[`setNeedsDisplay(_:)`](/documentation/QuartzCore/CALayer/setNeedsDisplay(_:))

Marks the region within the specified rectangle as needing to be updated.

[`needsDisplayOnBoundsChange`](/documentation/QuartzCore/CALayer/needsDisplayOnBoundsChange)

A Boolean indicating whether the layer contents must be updated when its bounds rectangle changes.

[`displayIfNeeded()`](/documentation/QuartzCore/CALayer/displayIfNeeded())

Initiates the update process for a layer if it is currently marked as needing an update.

[`needsDisplay()`](/documentation/QuartzCore/CALayer/needsDisplay())

Returns a Boolean indicating whether the layer has been marked as needing an update.

[`needsDisplay(forKey:)`](/documentation/QuartzCore/CALayer/needsDisplay(forKey:))

Returns a Boolean indicating whether changes to the specified key require the layer to be redisplayed.

### Layer animations

[`add(_:forKey:)`](/documentation/QuartzCore/CALayer/add(_:forKey:))

Add the specified animation object to the layer’s render tree.

[`animation(forKey:)`](/documentation/QuartzCore/CALayer/animation(forKey:))

Returns the animation object with the specified identifier.

[`removeAllAnimations()`](/documentation/QuartzCore/CALayer/removeAllAnimations())

Remove all animations attached to the layer.

[`removeAnimation(forKey:)`](/documentation/QuartzCore/CALayer/removeAnimation(forKey:))

Remove the animation object with the specified key.

[`animationKeys()`](/documentation/QuartzCore/CALayer/animationKeys())

Returns an array of strings that identify the animations currently attached to the layer.

### Managing layer resizing and layout

[`layoutManager`](/documentation/QuartzCore/CALayer/layoutManager)

The object responsible for laying out the layer’s sublayers.

[`setNeedsLayout()`](/documentation/QuartzCore/CALayer/setNeedsLayout())

Invalidates the layer’s layout and marks it as needing an update.

[`layoutSublayers()`](/documentation/QuartzCore/CALayer/layoutSublayers())

Tells the layer to update its layout.

[`layoutIfNeeded()`](/documentation/QuartzCore/CALayer/layoutIfNeeded())

Recalculate the receiver’s layout, if required.

[`needsLayout()`](/documentation/QuartzCore/CALayer/needsLayout())

Returns a Boolean indicating whether the layer has been marked as needing a layout update.

[`autoresizingMask`](/documentation/QuartzCore/CALayer/autoresizingMask)

A bitmask defining how the layer is resized when the bounds of its superlayer changes.

[`resize(withOldSuperlayerSize:)`](/documentation/QuartzCore/CALayer/resize(withOldSuperlayerSize:))

Informs the receiver that the size of its superlayer changed.

[`resizeSublayers(withOldSize:)`](/documentation/QuartzCore/CALayer/resizeSublayers(withOldSize:))

Informs the receiver’s sublayers that the receiver’s size has changed.

[`preferredFrameSize()`](/documentation/QuartzCore/CALayer/preferredFrameSize())

Returns the preferred size of the layer in the coordinate space of its superlayer.

### Managing layer constraints

[`constraints`](/documentation/QuartzCore/CALayer/constraints)

The constraints used to position current layer’s sublayers.

[`addConstraint(_:)`](/documentation/QuartzCore/CALayer/addConstraint(_:))

Adds the specified constraint to the layer.

### Getting the layer’s actions

[`action(forKey:)`](/documentation/QuartzCore/CALayer/action(forKey:))

Returns the action object assigned to the specified key.

[`actions`](/documentation/QuartzCore/CALayer/actions)

A dictionary containing layer actions.

[`defaultAction(forKey:)`](/documentation/QuartzCore/CALayer/defaultAction(forKey:))

Returns the default action for the current class.

### Mapping between coordinate and time spaces

[`convert(_:from:)`](/documentation/QuartzCore/CALayer/convert(_:from:)-8kl76)

Converts the point from the specified layer’s coordinate system to the receiver’s coordinate system.

[`convert(_:to:)`](/documentation/QuartzCore/CALayer/convert(_:to:)-7dcke)

Converts the point from the receiver’s coordinate system to the specified layer’s coordinate system.

[`convert(_:from:)`](/documentation/QuartzCore/CALayer/convert(_:from:)-4kx9l)

Converts the rectangle from the specified layer’s coordinate system to the receiver’s coordinate system.

[`convert(_:to:)`](/documentation/QuartzCore/CALayer/convert(_:to:)-tly5)

Converts the rectangle from the receiver’s coordinate system to the specified layer’s coordinate system.

[`convertTime(_:from:)`](/documentation/QuartzCore/CALayer/convertTime(_:from:))

Converts the time interval from the specified layer’s time space to the receiver’s time space.

[`convertTime(_:to:)`](/documentation/QuartzCore/CALayer/convertTime(_:to:))

Converts the time interval from the receiver’s time space to the specified layer’s time space

### Hit testing

[`hitTest(_:)`](/documentation/QuartzCore/CALayer/hitTest(_:))

Returns the farthest descendant of the receiver in the layer hierarchy (including itself) that contains the specified point.

[`contains(_:)`](/documentation/QuartzCore/CALayer/contains(_:))

Returns whether the receiver contains a specified point.

### Scrolling

[`visibleRect`](/documentation/QuartzCore/CALayer/visibleRect)

The visible region of the layer in its own coordinate space.

[`scroll(_:)`](/documentation/QuartzCore/CALayer/scroll(_:))

Initiates a scroll in the layer’s closest ancestor scroll layer so that the specified point lies at the origin of the scroll layer.

[`scrollRectToVisible(_:)`](/documentation/QuartzCore/CALayer/scrollRectToVisible(_:))

Initiates a scroll in the layer’s closest ancestor scroll layer so that the specified rectangle becomes visible.

### Identifying the layer

[`name`](/documentation/QuartzCore/CALayer/name)

The name of the receiver.

### Key-value coding extensions

[`shouldArchiveValue(forKey:)`](/documentation/QuartzCore/CALayer/shouldArchiveValue(forKey:))

Returns a Boolean indicating whether the value of the specified key should be archived.

[`defaultValue(forKey:)`](/documentation/QuartzCore/CALayer/defaultValue(forKey:))

Specifies the default value associated with the specified key.

### High dynamic range

[`preferredDynamicRange`](/documentation/QuartzCore/CALayer/preferredDynamicRange)

[`contentsHeadroom`](/documentation/QuartzCore/CALayer/contentsHeadroom)

[`wantsExtendedDynamicRangeContent`](/documentation/QuartzCore/CALayer/wantsExtendedDynamicRangeContent)

### Constants

[`CAAutoresizingMask`](/documentation/QuartzCore/CAAutoresizingMask)

These constants are used by the [`autoresizingMask`](/documentation/QuartzCore/CALayer/autoresizingMask) property.

[Action Identifiers](/documentation/QuartzCore/action-identifiers)

These constants are the predefined action identifiers used by [`action(forKey:)`](/documentation/QuartzCore/CALayer/action(forKey:)), [`add(_:forKey:)`](/documentation/QuartzCore/CALayer/add(_:forKey:)), [`defaultAction(forKey:)`](/documentation/QuartzCore/CALayer/defaultAction(forKey:)), [`removeAnimation(forKey:)`](/documentation/QuartzCore/CALayer/removeAnimation(forKey:)), Layer Filters, and the [`CAAction`](/documentation/QuartzCore/CAAction) protocol method [`run(forKey:object:arguments:)`](/documentation/QuartzCore/CAAction/run(forKey:object:arguments:)).

[`CAEdgeAntialiasingMask`](/documentation/QuartzCore/CAEdgeAntialiasingMask)

This mask is used by the [`edgeAntialiasingMask`](/documentation/QuartzCore/CALayer/edgeAntialiasingMask) property.

[Identity Transform](/documentation/QuartzCore/identity-transform)

Defines the identity transform matrix used by Core Animation.

[Scaling Filters](/documentation/QuartzCore/scaling-filters)

These constants specify the scaling filters used by [`magnificationFilter`](/documentation/QuartzCore/CALayer/magnificationFilter) and [`minificationFilter`](/documentation/QuartzCore/CALayer/minificationFilter).

[`CATransform3D`](/documentation/QuartzCore/CATransform3D)

The standard transform matrix used throughout Core Animation.

[`CALayer.DynamicRange`](/documentation/QuartzCore/CALayer/DynamicRange)

### Instance properties

[`cornerCurve`](/documentation/QuartzCore/CALayer/cornerCurve)

[`wantsDynamicContentScaling`](/documentation/QuartzCore/CALayer/wantsDynamicContentScaling)

### Type methods

[`cornerCurveExpansionFactor(_:)`](/documentation/QuartzCore/CALayer/cornerCurveExpansionFactor(_:))



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)