Mac Developer Library

Developer

QuartzCore Framework Reference CALayer Class Reference

Options
Deployment Target:

On This Page
Language:

CALayer

The CALayer class manages image-based content and allows you to perform animations on that content. 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 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 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 property) to manage the layout of subviews separately.

Import Statement


Swift

import QuartzCore

Objective-C

@import QuartzCore;

Availability


Available in OS X v10.5 and later.
  • Creates and returns an instance of the layer object.

    Declaration

    Objective-C

    + (instancetype)layer

    Return Value

    The initialized layer object or nil if initialization was not successful.

    Discussion

    If you subclass CALayer, you may override this method and use it to provide an instance of your specific subclass.

    Import Statement

    Objective-C

    @import QuartzCore;

    Availability

    Available in OS X v10.5 and later.

  • Returns an initialized CALayer object.

    Declaration

    Swift

    init!()

    Objective-C

    - (instancetype)init

    Return Value

    An initialized CALayer object.

    Discussion

    This is the designated initializer for layer objects that are not in the presentation layer.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

    See Also

    + layer

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

    Declaration

    Swift

    init!(layer layer: AnyObject!)

    Objective-C

    - (instancetype)initWithLayer:(id)layer

    Parameters

    layer

    The layer from which custom fields should be copied.

    Return Value

    A layer instance with any custom instance variables copied from layer.

    Discussion

    This initializer is used to create shadow copies of layers, for example, for the presentationLayer method. Using this method in any other situation will produce undefined behavior. For example, do not use this method to initialize a new layer with an existing layer’s content.

    If you are implementing a custom layer subclass, you can override this method and use it to copy the values of instance variables into the new object. Subclasses should always invoke the superclass implementation.

    This method is the designated initializer for layer objects in the presentation layer.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func presentationLayer() -> AnyObject!

    Objective-C

    - (id)presentationLayer

    Return Value

    A copy of the current presentation layer object.

    Discussion

    The layer object returned by this method provides a close approximation of the layer that is currently being displayed onscreen. While an animation is in progress, you can retrieve this object and use it to get the current values for those animations.

    The sublayers, mask, and superlayer properties of the returned layer return the corresponding objects from the presentation tree (not the model tree). This pattern also applies to any read-only layer methods. For example, the hitTest: method of the returned object queries the layer objects in the presentation tree.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func modelLayer() -> AnyObject!

    Objective-C

    - (id)modelLayer

    Return Value

    A layer instance representing the underlying model layer.

    Discussion

    Calling this method on a layer in the presentation tree returns the corresponding layer object in the model tree. This method returns a value only when a transaction involving changes to the presentation layer is in progress. If no transaction is in progress, the results of calling this method are undefined.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • delegate delegate Property

    The layer’s delegate object.

    Declaration

    Swift

    weak var delegate: AnyObject!

    Objective-C

    @property(weak) id delegate

    Discussion

    You can use a delegate object to provide the layer’s contents, handle the layout of any sublayers, and provide custom actions in response to layer-related changes. The object you assign to this property should implement one or more of the methods of the CALayerDelegate informal protocol. For more information about that protocol, see CALayerDelegate Informal Protocol Reference

    In iOS, if the layer is associated with a UIView object, this property must be set to the view that owns the layer.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • contents contents Property

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

    Declaration

    Swift

    var contents: AnyObject!

    Objective-C

    @property(strong) id contents

    Discussion

    The default value of this property is nil.

    If you are using the layer to display a static image, you can set this property to the CGImageRef containing the image you want to display. (In OS X 10.6 and later, you can also set the property to an NSImage object.) Assigning a value to this property causes the layer to use your image rather than create a separate backing store.

    If the layer object is tied to a view object, you should avoid setting the contents of this property directly. The interplay between views and layers usually results in the view replacing the contents of this property during a subsequent update.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

    See Also

    contentsRect

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

    Declaration

    Swift

    var contentsRect: CGRect

    Objective-C

    @property CGRect contentsRect

    Discussion

    Defaults to the unit rectangle (0.0, 0.0, 1.0, 1.0).

    If pixels outside the unit rectangle are requested, the edge pixels of the contents image will be extended outwards.

    If an empty rectangle is provided, the results are undefined.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

    See Also

    contents

  • The rectangle that defines how the layer contents are scaled during a resizing operation. Animatable.

    Declaration

    Swift

    var contentsCenter: CGRect

    Objective-C

    @property CGRect contentsCenter

    Discussion

    You can use this property to subdivide the layer’s content into a 3x3 grid. The value in this property specifies the location and size of the center rectangle in that grid. If the layer’s contentsGravity property is set to one of the resizing modes, resizing the layer causes scaling to occur differently in each rectangle of the grid. The center rectangle is stretched in both dimensions, the top-center and bottom-center rectangles are stretched only horizontally, the left-center and right-center rectangles are stretched only vertically, and the four corner rectangles are not stretched at all. Therefore, you can use this technique to implement stretchable backgrounds or images using a three-part or nine-part image.

    The value in this property is set to the unit rectangle (0.0,0.0) (1.0,1.0) by default, which causes the entire image to scale in both dimensions. If you specify a rectangle that extends outside the unit rectangle, the result is undefined. The rectangle you specify is applied only after the contentsRect property has been applied to the image.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.6 and later.

  • Reloads the content of this layer.

    Declaration

    Swift

    func display()

    Objective-C

    - (void)display

    Discussion

    Do not call this method directly. The layer calls this method at appropriate times to update the layer’s content. If the layer has a delegate object, this method attempts to call the delegate’s displayLayer: method, which the delegate can use to update the layer’s contents. If the delegate does not implement the displayLayer: method, this method creates a backing store and calls the layer’s drawInContext: method to fill that backing store with content. The new backing store replaces the previous contents of the layer.

    Subclasses can override this method and use it to set the layer’s contents property directly. You might do this if your custom layer subclass handles layer updates differently.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func drawInContext(_ ctx: CGContext!)

    Objective-C

    - (void)drawInContext:(CGContextRef)ctx

    Parameters

    ctx

    The graphics context in which to draw the content. The context may be clipped to protect valid layer content. Subclasses that wish to find the actual region to draw can call CGContextGetClipBoundingBox.

    Discussion

    The default implementation of this method does not doing any drawing itself. If the layer’s delegate implements the drawLayer:inContext: method, that method is called to do the actual drawing.

    Subclasses can override this method and use it to draw the layer’s content. When drawing, all coordinates should be specified in points in the logical coordinate space.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    var contentsGravity: String!

    Objective-C

    @property(copy) NSString *contentsGravity

    Discussion

    The possible values for this property are listed in “Contents Gravity Values”. The default value of this property is kCAGravityResize.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • opacity opacity Property

    The opacity of the receiver. Animatable.

    Declaration

    Swift

    var opacity: Float

    Objective-C

    @property float opacity

    Discussion

    The value of this property must be in the range 0.0 (transparent) to 1.0 (opaque). Values outside that range are clamped to the minimum or maximum. The default value of this property is 1.0.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • hidden hidden Property

    A Boolean indicating whether the layer is displayed. Animatable.

    Declaration

    Swift

    var hidden: Bool

    Objective-C

    @property(getter=isHidden) BOOL hidden

    Discussion

    The default value of this property is NOfalse.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    var masksToBounds: Bool

    Objective-C

    @property BOOL masksToBounds

    Discussion

    When the value of this property is YEStrue, Core Animation creates an implicit clipping mask that matches the bounds of the layer and includes any corner radius effects. If a value for the mask property is also specified, the two masks are multiplied to get the final mask value.

    The default value of this property is NOfalse.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • mask mask Property

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

    Declaration

    Swift

    var mask: CALayer!

    Objective-C

    @property(strong) CALayer *mask

    Discussion

    The layer’s alpha channel determines how much of the layer’s content and background shows through. Fully or partially opaque pixels allow the underlying content to show through but fully transparent pixels block that content.

    The default value of this property is nil nil. When configuring a mask, remember to set the size and position of the mask layer to ensure it is aligned properly with the layer it masks.

    Special Considerations

    The layer you assign to this property must not have a superlayer. If it does, the behavior is undefined.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

    See Also

    masksToBounds

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

    Declaration

    Swift

    var doubleSided: Bool

    Objective-C

    @property(getter=isDoubleSided) BOOL doubleSided

    Discussion

    When the value in this property is NOfalse, the layer hides its content when it faces away from the viewer. The default value of this property is YEStrue.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    var cornerRadius: CGFloat

    Objective-C

    @property CGFloat cornerRadius

    Discussion

    Setting the radius to a value greater than 0.0 causes the layer to begin drawing rounded corners on its background. By default, the corner radius does not apply to the image in the layer’s contents property; it applies only to the background color and border of the layer. However, setting the masksToBounds property to YEStrue causes the content to be clipped to the rounded corners.

    The default value of this property is 0.0.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • The width of the layer’s border. Animatable.

    Declaration

    Swift

    var borderWidth: CGFloat

    Objective-C

    @property CGFloat borderWidth

    Discussion

    When this value is greater than 0.0, the layer draws a border using the current borderColor value. The border is drawn inset from the receiver’s bounds by the value specified in this property. It is composited above the receiver’s contents and sublayers and includes the effects of the cornerRadius property.

    The default value of this property is 0.0.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • The color of the layer’s border. Animatable.

    Declaration

    Swift

    var borderColor: CGColor!

    Objective-C

    @property CGColorRef borderColor

    Discussion

    The default value of this property is an opaque black color.

    The value of this property is retained using the Core Foundation retain/release semantics. This behavior occurs despite the fact that the property declaration appears to use the default assign semantics for object retention.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • The background color of the receiver. Animatable.

    Declaration

    Swift

    var backgroundColor: CGColor!

    Objective-C

    @property CGColorRef backgroundColor

    Discussion

    The default value of this property is nil.

    The value of this property is retained using the Core Foundation retain/release semantics. This behavior occurs despite the fact that the property declaration appears to use the default assign semantics for object retention.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • The opacity of the layer’s shadow. Animatable.

    Declaration

    Swift

    var shadowOpacity: Float

    Objective-C

    @property float shadowOpacity

    Discussion

    The value in this property must be in the range 0.0 (transparent) to 1.0 (opaque). The default value of this property is 0.0.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    var shadowRadius: CGFloat

    Objective-C

    @property CGFloat shadowRadius

    Discussion

    You specify the radius The default value of this property is 3.0.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    var shadowOffset: CGSize

    Objective-C

    @property CGSize shadowOffset

    Discussion

    The default value of this property is (0.0, -3.0).

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • The color of the layer’s shadow. Animatable.

    Declaration

    Swift

    var shadowColor: CGColor!

    Objective-C

    @property CGColorRef shadowColor

    Discussion

    The default value of this property is an opaque black color.

    The value of this property is retained using the Core Foundation retain/release semantics. This behavior occurs despite the fact that the property declaration appears to use the default assign semantics for object retention.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • The shape of the layer’s shadow. Animatable.

    Declaration

    Swift

    var shadowPath: CGPath!

    Objective-C

    @property CGPathRef shadowPath

    Discussion

    The default value of this property is nil, which causes the layer to use a standard shadow shape. If you specify a value for this property, the layer creates its shadow using the specified path instead of the layer’s composited alpha channel. The path you provide defines the outline of the shadow. It is filled using the non-zero winding rule and the current shadow color, opacity, and blur radius.

    Unlike most animatable properties, this property (as with all CGPathRef animatable properties) does not support implicit animation. However, the path object may be animated using any of the concrete subclasses of CAPropertyAnimation. Paths will interpolate as a linear blend of the "on-line" points; "off-line" points may be interpolated non-linearly (to preserve continuity of the curve's derivative). If the two paths have a different number of control points or segments, the results are undefined. If the path extends outside the layer bounds it will not automatically be clipped to the layer, only if the normal layer masking rules cause that.

    Specifying an explicit path usually improves rendering performance.

    The value of this property is retained using the Core Foundation retain/release semantics. This behavior occurs despite the fact that the property declaration appears to use the default assign semantics for object retention.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.7 and later.

  • style style Property

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

    Declaration

    Swift

    var style: [NSObject : AnyObject]!

    Objective-C

    @property(copy) NSDictionary *style

    Discussion

    This dictionary may in turn have a style key, forming a hierarchy of default values. In the case of hierarchical style dictionaries the shallowest value for a property is used. For example, the value for “style.someValue” takes precedence over “style.style.someValue”.

    If the style dictionary does not define a value for an attribute, the receiver’s defaultValueForKey: method is called. The default value of this property is nil.

    The style dictionary is not consulted for the following keys: bounds, frame.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • filters filters Property

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

    Declaration

    Swift

    var filters: [AnyObject]!

    Objective-C

    @property(copy) NSArray *filters

    Discussion

    The filters you add to this property affect the content of the layer, including its border, filled background and sublayers. The default value of this property is nil.

    Changing the inputs of the CIFilter object directly after it is attached to the layer causes undefined behavior. It is possible to modify filter parameters after attaching them to the layer but you must use the layer’s setValue:forKeyPath: method to do so. In addition, you must assign a name to the filter so that you can identify it in the array. For example, to change the inputScale parameter of the filter, you could use code similar to the following:

    • CIFilter *filter = ...;
    • CALayer *layer = ...;
    • filter.name = @"myFilter";
    • layer.filters = [NSArray arrayWithObject:filter];
    • [layer setValue:[NSNumber numberWithInt:1] forKeyPath:@"filters.myFilter.inputScale"];

    Special Considerations

    This property is not supported on layers in iOS.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    var compositingFilter: AnyObject!

    Objective-C

    @property(strong) id compositingFilter

    Discussion

    The default value of this property is nil, which causes the layer to use source-over compositing.

    In OS X, it is possible to modify the filter’s parameters after attaching it to the layer but you must use the layer’s setValue:forKeyPath: method to do so. For example, to change the inputScale parameter of the filter, you could use code similar to the following:

    • CIFilter *filter = ...;
    • CALayer *layer = ...;
    • layer.compositingFilter = filter;
    • [layer setValue:[NSNumber numberWithInt:1] forKeyPath:@"compositingFilter.inputScale"];

    Changing the inputs of the CIFilter object directly after it is attached to the layer causes undefined behavior.

    Special Considerations

    This property is not supported on layers in iOS.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    var backgroundFilters: [AnyObject]!

    Objective-C

    @property(copy) NSArray *backgroundFilters

    Discussion

    Background filters affect the content behind the layer that shows through into the layer itself. Typically this content belongs to the superlayer that acts as the parent of the layer. These filters do not affect the content of the layer itself, including the layer’s background color and border. They also do not affect content outside of the layer’s bounds.

    The default value of this property is nil.

    Changing the inputs of the CIFilter object directly after it is attached to the layer causes undefined behavior. In OS X, it is possible to modify filter parameters after attaching them to the layer but you must use the layer’s setValue:forKeyPath: method to do so. In addition, you must assign a name to the filter so that you can identify it in the array. For example, to change the inputScale parameter of the filter, you could use code similar to the following:

    • CIFilter *filter = ...;
    • CALayer *layer = ...;
    • filter.name = @"myFilter";
    • layer.backgroundFilters = [NSArray arrayWithObject:filter];
    • [layer setValue:[NSNumber numberWithInt:1] forKeyPath:@"backgroundFilters.myFilter.inputScale"];

    Special Considerations

    This property is not supported on layers in iOS.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • The filter used when reducing the size of the content.

    Declaration

    Swift

    var minificationFilter: String!

    Objective-C

    @property(copy) NSString *minificationFilter

    Discussion

    The possible values for this property are listed in “Scaling Filters”.

    The default value of this property is kCAFilterLinear.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    var minificationFilterBias: Float

    Objective-C

    @property float minificationFilterBias

    Discussion

    This value is used by the minificationFilter when it is set to kCAFilterTrilinear.

    The default value of this property is 0.0.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.6 and later.

  • The filter used when increasing the size of the content.

    Declaration

    Swift

    var magnificationFilter: String!

    Objective-C

    @property(copy) NSString *magnificationFilter

    Discussion

    The possible values for this property are listed in “Scaling Filters”.

    The default value of this property is kCAFilterLinear.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • opaque opaque Property

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

    Declaration

    Swift

    var opaque: Bool

    Objective-C

    @property(getter=isOpaque) BOOL opaque

    Discussion

    The default value of this property is NOfalse. If your app draws completely opaque content that fills the layer’s bounds, setting this property to YEStrue lets the system optimize the rendering behavior for the layer. Specifically, when the layer creates the backing store for your drawing commands, Core Animation omits the alpha channel of that backing store. Doing so can improve the performance of compositing operations. If you set the value of this property to YEStrue, you must fill the layer’s bounds with opaque content.

    Setting this property affects only the backing store managed by Core Animation. If you assign an image with an alpha channel to the layer’s contents property, that image retains its alpha channel regardless of the value of this property.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    var edgeAntialiasingMask: CAEdgeAntialiasingMask

    Objective-C

    @property CAEdgeAntialiasingMask edgeAntialiasingMask

    Discussion

    This property specifies which edges of the layer are antialiased and is a combination of the constants defined in Edge Antialiasing Mask. You can enable or disable antialiasing for each edge (top, left, bottom, right) separately. By default antialiasing is enabled for all edges.

    Typically, you would use this property to disable antialiasing for edges that abut edges of other layers, to eliminate the seams that would otherwise occur.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func contentsAreFlipped() -> Bool

    Objective-C

    - (BOOL)contentsAreFlipped

    Return Value

    YEStrue if the layer contents are implicitly flipped when rendered or NOfalse if they are not. This method returns NOfalse by default.

    Discussion

    This method provides information about whether the layer’s contents are being flipped during drawing. You should not attempt to override this method and return a different value.

    If the layer needs to flip its content, it returns YEStrue from this method and applies a y-flip transform to the graphics context before passing it to the layer’s drawInContext: method. Similarly, the layer converts any rectangles passed to its setNeedsDisplayInRect: into the flipped coordinate space.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.6 and later.

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

    Declaration

    Swift

    var geometryFlipped: Bool

    Objective-C

    @property(getter=isGeometryFlipped) BOOL geometryFlipped

    Discussion

    If the layer is providing the backing for a layer-backed view, the view is responsible for managing the value in this property. For standalone layers, this property controls whether geometry values for the layer are interpreted using the standard or flipped coordinate system. The value of this property does not affect the rendering of the layer’s content.

    The default value of this property is NOfalse.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.6 and later.

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

    Declaration

    Swift

    var drawsAsynchronously: Bool

    Objective-C

    @property BOOL drawsAsynchronously

    Discussion

    When this property is set to YEStrue, the graphics context used to draw the layer’s contents queues drawing commands and executes them on a background thread rather than executing them synchronously. Performing these commands asynchronously can improve performance in some apps. However, you should always measure the actual performance benefits before enabling this capability.

    The default value for this property is NOfalse.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.8 and later.

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

    Declaration

    Swift

    var shouldRasterize: Bool

    Objective-C

    @property BOOL shouldRasterize

    Discussion

    When the value of this property is YEStrue, the layer is rendered as a bitmap in its local coordinate space and then composited to the destination with any other content. Shadow effects and any filters in the filters property are rasterized and included in the bitmap. However, the current opacity of the layer is not rasterized. If the rasterized bitmap requires scaling during compositing, the filters in the minificationFilter and magnificationFilter properties are applied as needed.

    When the value of this property is NOfalse, the layer is composited directly into the destination whenever possible. The layer may still be rasterized prior to compositing if certain features of the compositing model (such as the inclusion of filters) require it.

    The default value of this property is NOfalse.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.7 and later.

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

    Declaration

    Swift

    var rasterizationScale: CGFloat

    Objective-C

    @property CGFloat rasterizationScale

    Discussion

    When the value in the shouldRasterize property is YEStrue, the layer uses this property to determine whether to scale the rasterized content (and by how much). The default value of this property is 1.0, which indicates that the layer should be rasterized at its current size. Larger values magnify the content and smaller values shrink it.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.7 and later.

  • Renders the receiver and its sublayers into the specified context.

    Declaration

    Swift

    func renderInContext(_ ctx: CGContext!)

    Objective-C

    - (void)renderInContext:(CGContextRef)ctx

    Parameters

    ctx

    The graphics context to use to render the layer.

    Discussion

    This method renders directly from the layer tree, ignoring any animations added to the render tree. Renders in the coordinate space of the layer.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • frame frame Property

    The layer’s frame rectangle.

    Declaration

    Swift

    var frame: CGRect

    Objective-C

    @property CGRect frame

    Discussion

    The frame rectangle is position and size of the layer specified in the superlayer’s coordinate space. For layers, the frame rectangle is a computed property that is derived from the values in thebounds, anchorPoint and position properties. When you assign a new value to this property, the layer changes its position and bounds properties to match the rectangle you specified. The values of each coordinate in the rectangle are measured in points.

    For more information about the relationship between the frame, bounds, anchorPoint and position properties, see Core Animation Programming Guide.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • bounds bounds Property

    The layer’s bounds rectangle. Animatable.

    Declaration

    Swift

    var bounds: CGRect

    Objective-C

    @property CGRect bounds

    Discussion

    The bounds rectangle is the origin and size of the layer in its own coordinate space. When you create a new standalone layer, the default value for this property is an empty rectangle, which you must change before using the layer. The values of each coordinate in the rectangle are measured in points.

    For more information about the relationship between the frame, bounds, anchorPoint and position properties, see Core Animation Programming Guide.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • position position Property

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

    Declaration

    Swift

    var position: CGPoint

    Objective-C

    @property CGPoint position

    Discussion

    The value of this property is specified in points and is always specified relative to the value in the anchorPoint property. For new standalone layers, the default position is set to (0.0, 0.0). Changing the frame property also updates the value in this property.

    For more information about the relationship between the frame, bounds, anchorPoint and position properties, see Core Animation Programming Guide.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

    See Also

    anchorPoint

  • zPosition zPosition Property

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

    Declaration

    Swift

    var zPosition: CGFloat

    Objective-C

    @property CGFloat zPosition

    Discussion

    The default value of this property is 0. Changing the value of this property changes the the front-to-back ordering of layers onscreen. This can affect the visibility of layers whose frame rectangles overlap.

    The value of this property is measured in points.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    var anchorPointZ: CGFloat

    Objective-C

    @property CGFloat anchorPointZ

    Discussion

    This property specifies the anchor point on the z axis around which geometric manipulations occur. The point is expressed as a distance (measured in points) along the z axis. The default value of this property is 0.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.6 and later.

    See Also

    anchorPoint

  • Defines the anchor point of the layer's bounds rectangle. Animatable.

    Declaration

    Swift

    var anchorPoint: CGPoint

    Objective-C

    @property CGPoint anchorPoint

    Discussion

    You specify the value for this property using the unit coordinate space. The default value of this property is (0.5, 0.5), which represents the center of the layer’s bounds rectangle. All geometric manipulations to the view occur about the specified point. For example, applying a rotation transform to a layer with the default anchor point causes the layer to rotate around its center. Changing the anchor point to a different location would cause the layer to rotate around that new point.

    For more information about the relationship between the frame, bounds, anchorPoint and position properties, see Core Animation Programming Guide.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

    See Also

    position

  • The scale factor applied to the layer.

    Declaration

    Swift

    var contentsScale: CGFloat

    Objective-C

    @property CGFloat contentsScale

    Discussion

    This value defines the mapping between the logical coordinate space of the layer (measured in points) and the physical coordinate space (measured in pixels). Higher scale factors indicate that each point in the layer is represented by more than one pixel at render time. For example, if the scale factor is 2.0 and the layer’s bounds are 50 x 50 points, the size of the bitmap used to present the layer’s content is 100 x 100 pixels.

    The default value of this property is 1.0. For layers attached to a view, the view changes the scale factor automatically to a value that is appropriate for the current screen. For layers you create and manage yourself, you must set the value of this property yourself based on the resolution of the screen and the content you are providing. Core Animation uses the value you specify as a cue to determine how to render your content.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.7 and later.

  • transform transform Property

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

    Declaration

    Swift

    var transform: CATransform3D

    Objective-C

    @property CATransform3D transform

    Discussion

    This property is set to the identity transform by default. Any transformations you apply to the layer occur relative to the layer’s anchor point.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    var sublayerTransform: CATransform3D

    Objective-C

    @property CATransform3D sublayerTransform

    Discussion

    You typically use this property to add perspective and other viewing effects to embedded layers. You add perspective by setting the sublayer transform to the desired projection matrix. The default value of this property is the identity transform.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • Returns an affine version of the layer’s transform.

    Declaration

    Swift

    func affineTransform() -> CGAffineTransform

    Objective-C

    - (CGAffineTransform)affineTransform

    Return Value

    The affine transform structure that corresponds to the value in the layer’s transform property.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func setAffineTransform(_ m: CGAffineTransform)

    Objective-C

    - (void)setAffineTransform:(CGAffineTransform)m

    Parameters

    m

    The affine transform to use for the layer’s transform.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • sublayers sublayers Property

    An array containing the layer’s sublayers.

    Declaration

    Swift

    var sublayers: [AnyObject]!

    Objective-C

    @property(copy) NSArray *sublayers

    Discussion

    The sublayers are listed in back to front order. The default value of this property is nil.

    Special Considerations

    When setting the sublayers property to an array populated with layer objects, each layer in the array must not already have a superlayer—that is, its superlayer property must currently be nil.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • The superlayer of the layer. (read-only)

    Declaration

    Swift

    var superlayer: CALayer! { get }

    Objective-C

    @property(readonly) CALayer *superlayer

    Discussion

    The superlayer manages the layout of its sublayers.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func addSublayer(_ aLayer: CALayer!)

    Objective-C

    - (void)addSublayer:(CALayer *)aLayer

    Parameters

    aLayer

    The layer to be added.

    Discussion

    If the array in the sublayers property is nil, calling this method creates an array for that property and adds the specified layer to it.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • Detaches the layer from its parent layer.

    Declaration

    Swift

    func removeFromSuperlayer()

    Objective-C

    - (void)removeFromSuperlayer

    Discussion

    You can use this method to remove a layer (and all of its sublayers) from a layer hierarchy. This method updates both the superlayer’s list of sublayers and sets this layer’s superlayer property to nil.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func insertSublayer(_ aLayer: CALayer!, atIndex index: UInt32)

    Objective-C

    - (void)insertSublayer:(CALayer *)aLayer atIndex:(unsigned int)index

    Parameters

    aLayer

    The sublayer to be inserted into the current layer.

    index

    The index at which to insert aLayer. This value must be a valid 0-based index into the sublayers array.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func insertSublayer(_ aLayer: CALayer!, below sublayer: CALayer!)

    Objective-C

    - (void)insertSublayer:(CALayer *)aLayer below:(CALayer *)sublayer

    Parameters

    aLayer

    The sublayer to be inserted into the current layer.

    sublayer

    An existing sublayer in the current layer. The layer in aLayer is inserted before this layer in the sublayers array, and thus appears behind it visually.

    Discussion

    If sublayer is not in the receiver’s sublayers array, this method raises an exception.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func insertSublayer(_ aLayer: CALayer!, above sublayer: CALayer!)

    Objective-C

    - (void)insertSublayer:(CALayer *)aLayer above:(CALayer *)sublayer

    Parameters

    aLayer

    The sublayer to be inserted into the current layer.

    sublayer

    An existing sublayer in the current layer. The layer in aLayer is inserted after this layer in the sublayers array, and thus appears in front of it visually.

    Special Considerations

    If sublayer is not in the receiver’s sublayers array, this method raises an exception.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • Replaces the specified sublayer with a different layer object.

    Declaration

    Swift

    func replaceSublayer(_ oldLayer: CALayer!, with newLayer: CALayer!)

    Objective-C

    - (void)replaceSublayer:(CALayer *)oldLayer with:(CALayer *)newLayer

    Parameters

    oldLayer

    The layer to be replaced.

    newLayer

    The layer with which to replace oldLayer.

    Discussion

    If oldLayer is not in the receiver’s sublayers array, the behavior of this method is undefined.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func setNeedsDisplay()

    Objective-C

    - (void)setNeedsDisplay

    Discussion

    Calling this method causes the layer to recache its content. This results in the layer potentially calling either the displayLayer: or drawLayer:inContext: method of its delegate. The existing content in the layer’s contents property is removed to make way for the new content.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func setNeedsDisplayInRect(_ theRect: CGRect)

    Objective-C

    - (void)setNeedsDisplayInRect:(CGRect)theRect

    Parameters

    theRect

    The rectangular region of the layer to mark as invalid. You must specify this rectangle in the layer’s own coordinate system.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    var needsDisplayOnBoundsChange: Bool

    Objective-C

    @property BOOL needsDisplayOnBoundsChange

    Discussion

    When this property is set to YEStrue, the layer automatically calls its setNeedsDisplay method whenever its bounds property changes. The default value of this property is NOfalse.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func displayIfNeeded()

    Objective-C

    - (void)displayIfNeeded

    Discussion

    You can call this method as needed to force an update to your layer’s contents outside of the normal update cycle. Doing so is generally not needed, though. The preferred way to update a layer is to call setNeedsDisplay and let the system update the layer during the next cycle.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.6 and later.

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

    Declaration

    Swift

    func needsDisplay() -> Bool

    Objective-C

    - (BOOL)needsDisplay

    Return Value

    YEStrue if the layer needs to be updated.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.6 and later.

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

    Declaration

    Swift

    class func needsDisplayForKey(_ key: String!) -> Bool

    Objective-C

    + (BOOL)needsDisplayForKey:(NSString *)key

    Parameters

    key

    A string that specifies an attribute of the layer.

    Return Value

    YEStrue if the layer requires a redisplay.

    Discussion

    Subclasses can override this method and return YEStrue if the layer should be redisplayed when the value of the specified attribute changes. Animations changing the value of the attribute also trigger redisplay.

    The default implementation of this method returns NOfalse.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.6 and later.

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

    Declaration

    Swift

    func addAnimation(_ anim: CAAnimation!, forKey key: String!)

    Objective-C

    - (void)addAnimation:(CAAnimation *)anim forKey:(NSString *)key

    Parameters

    anim

    The animation to be added to the render tree. This object is copied by the render tree, not referenced. Therefore, subsequent modifications to the object are not propagated into the render tree.

    key

    A string that identifies the animation. Only one animation per unique key is added to the layer. The special key kCATransition is automatically used for transition animations. You may specify nil for this parameter.

    Discussion

    If the duration property of the animation is zero or negative, the duration is changed to the current value of the kCATransactionAnimationDuration transaction property (if set) or to the default value of 0.25 seconds.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • Returns the animation object with the specified identifier.

    Declaration

    Swift

    func animationForKey(_ key: String!) -> CAAnimation!

    Objective-C

    - (CAAnimation *)animationForKey:(NSString *)key

    Parameters

    key

    A string that specifies the identifier of the animation. This string corresponds to the identifier string you passed to the addAnimation:forKey: method.

    Return Value

    The animation object matching the identifier, or nil if no such animation exists.

    Discussion

    You can use this string to retrieve animation objects already associated with a layer. However, you must not modify any properties of the returned object. Doing so will result in undefined behavior.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • Remove all animations attached to the layer.

    Declaration

    Swift

    func removeAllAnimations()

    Objective-C

    - (void)removeAllAnimations

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • Remove the animation object with the specified key.

    Declaration

    Swift

    func removeAnimationForKey(_ key: String!)

    Objective-C

    - (void)removeAnimationForKey:(NSString *)key

    Parameters

    key

    The identifier of the animation to remove.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func animationKeys() -> [AnyObject]!

    Objective-C

    - (NSArray *)animationKeys

    Return Value

    An array of NSString objects identifying the current animations.

    Discussion

    The order of the array matches the order in which animations will be applied to the layer.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.6 and later.

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

    Declaration

    Swift

    var layoutManager: AnyObject!

    Objective-C

    @property(strong) id layoutManager

    Discussion

    The object you assign to this property must nominally implement the CALayoutManager Informal Protocol informal protocol. If the layer’s delegate does not handle layout updates, the object assigned to this property is given a chance to update the layout of the layer’s sublayers.

    In OS X, assign an instance of the CAConstraintLayoutManager class to this property if your layer uses layer-based constraints to handle layout changes.

    The default value of this property is nil.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func setNeedsLayout()

    Objective-C

    - (void)setNeedsLayout

    Discussion

    You can call this method to indicate that the layout of a layer’s sublayers has changed and must be updated. The system typically calls this method automatically when the layer’s bounds change or when sublayers are added or removed. In OS X, if your layer’s layoutManager property contains an object that implements the invalidateLayoutOfLayer: method, that method is called too.

    During the next update cycle, the system calls the layoutSublayers method of any layers requiring layout updates.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • Tells the layer to update its layout.

    Declaration

    Swift

    func layoutSublayers()

    Objective-C

    - (void)layoutSublayers

    Discussion

    Subclasses can override this method and use it to implement their own layout algorithm. Your implementation must set the frame of each sublayer managed by the receiver.

    The default implementation of this method calls the layoutSublayersOfLayer: method of the layer’s delegate object. If there is no delegate object, or the delegate does not implement that method, this method calls the layoutSublayersOfLayer: method of the object in the layoutManager property.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • Recalculate the receiver’s layout, if required.

    Declaration

    Swift

    func layoutIfNeeded()

    Objective-C

    - (void)layoutIfNeeded

    Discussion

    When this message is received, the layer’s super layers are traversed until a ancestor layer is found that does not require layout. Then layout is performed on the entire layer-tree beneath that ancestor.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func needsLayout() -> Bool

    Objective-C

    - (BOOL)needsLayout

    Return Value

    YEStrue if the layer has been marked as requiring a layout update.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.6 and later.

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

    Declaration

    Swift

    var autoresizingMask: CAAutoresizingMask

    Objective-C

    @property CAAutoresizingMask autoresizingMask

    Discussion

    If your app does not use a layout manager or constraints to handle layout changes, you can assign a value to this property to adjust the layer’s size in response to changes in the superlayer’s bounds. For a list of possible values, see “Autoresizing Mask”.

    The default value of this property is kCALayerNotSizable.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • Informs the receiver that the size of its superlayer changed.

    Declaration

    Swift

    func resizeWithOldSuperlayerSize(_ size: CGSize)

    Objective-C

    - (void)resizeWithOldSuperlayerSize:(CGSize)size

    Parameters

    size

    The previous size of the superlayer.

    Discussion

    When the autoresizingMask property is used for resizing and the bounds of a layer change, that layer calls this method on each of its sublayers. Sublayers use this method to adjust their own frame rectangles to reflect the new superlayer bounds, which can be retrieved directly from the superlayer. The old size of the superlayer is passed to this method so that the sublayer has that information for any calculations it must make.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func resizeSublayersWithOldSize(_ size: CGSize)

    Objective-C

    - (void)resizeSublayersWithOldSize:(CGSize)size

    Parameters

    size

    The previous size of the current layer.

    Discussion

    When the autoresizingMask property is used for resizing and the bounds of this layer change, the layer calls this method. The default implementation calls the resizeWithOldSuperlayerSize: method of each sublayer to let it know its superlayer’s bounds changed. You should not need to call or override this method directly.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func preferredFrameSize() -> CGSize

    Objective-C

    - (CGSize)preferredFrameSize

    Return Value

    The layer’s preferred frame size.

    Discussion

    In OS X, the default implementation of this method calls the preferredSizeOfLayer: method of its layout manager—that is, the object in its layoutManager property. If that object does not exist or does not implement that method, this method returns the size of the layer’s current bounds rectangle mapped into the coordinate space of its superlayer.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • The constraints used to position current layer’s sublayers.

    Declaration

    Swift

    var constraints: [AnyObject]!

    Objective-C

    @property(copy) NSArray *constraints

    Discussion

    OS X apps can use this property to access their layer-based constraints. Before constraints can be applied, you must also assign a CAConstraintLayoutManager object to the layoutManager property of the layer.

    iOS apps do not support layer-based constraints.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • Adds the specified constraint to the layer.

    Declaration

    Swift

    func addConstraint(_ aConstraint: CAConstraint!)

    Objective-C

    - (void)addConstraint:(CAConstraint *)aConstraint

    Parameters

    aConstraint

    The constraint object to add to the receiver’s array of constraint objects.

    Discussion

    In OS X, you typically add constraints to a layer to manage the size and position of that layer’s sublayers. Before constraints can be applied, you must also assign a CAConstraintLayoutManager object to the layoutManager property of the layer. For more information about managing layer-based constraints, see Core Animation Programming Guide.

    iOS apps do not support layer-based constraints.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • Returns the action object assigned to the specified key.

    Declaration

    Swift

    func actionForKey(_ key: String!) -> CAAction!

    Objective-C

    - (id<CAAction>)actionForKey:(NSString *)key

    Parameters

    key

    The identifier of the action.

    Return Value

    Returns the object that provides the action for key. The object must implement the CAAction protocol.

    Discussion

    This method searches for the given action object of the layer. Actions define dynamic behaviors for a layer. For example, the animatable properties of a layer typically have corresponding action objects to initiate the actual animations. When that property changes, the layer looks for the action object associated with the property name and executes it. You can also associate custom action objects with your layer to implement app-specific actions.

    This method searches for the layer’s associated actions in the following order:

    1. If the layer has a delegate that implements the actionForLayer:forKey: method, the layer calls that method. The delegate must do one of the following:

      • Return the action object for the given key.

      • Return the NSNull object if it does not handle the action.

    2. The layer looks in the layer’s actions dictionary for a matching key/action pair.

    3. The layer looks in the style dictionary for an actions dictionary for a matching key/action pair.

    4. The layer calls the defaultActionForKey: class method to look for any class-defined actions.

    If any of the above steps returns an instance of NSNull, it is converted to nil before continuing.

    When an action object is invoked it receives three parameters: the name of the event, the object on which the event happened (the layer), and a dictionary of named arguments specific to each event kind.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • actions actions Property

    A dictionary containing layer actions.

    Declaration

    Swift

    var actions: [NSObject : AnyObject]!

    Objective-C

    @property(copy) NSDictionary *actions

    Discussion

    The default value of this property is nil. You can use this dictionary to store custom actions for your layer. The contents of this dictionary searched as part of the standard implementation of the actionForKey: method.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • Returns the default action for the current class.

    Declaration

    Swift

    class func defaultActionForKey(_ key: String!) -> CAAction!

    Objective-C

    + (id<CAAction>)defaultActionForKey:(NSString *)key

    Parameters

    key

    The identifier of the action.

    Return Value

    Returns a suitable action object for the given key or nil of no action object was associated with that key.

    Discussion

    Classes that want to provide default actions can override this method and use it to return those actions.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func convertPoint(_ aPoint: CGPoint, fromLayer layer: CALayer!) -> CGPoint

    Objective-C

    - (CGPoint)convertPoint:(CGPoint)aPoint fromLayer:(CALayer *)layer

    Parameters

    aPoint

    A point specifying a location in the coordinate system of layer.

    layer

    The layer with aPoint in its coordinate system. The receiver and layer and must share a common parent layer. This parameter may be nil.

    Return Value

    The point converted to the receiver’s coordinate system.

    Discussion

    If you specify nil for the layer parameter, this method returns the original point.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func convertPoint(_ aPoint: CGPoint, toLayer layer: CALayer!) -> CGPoint

    Objective-C

    - (CGPoint)convertPoint:(CGPoint)aPoint toLayer:(CALayer *)layer

    Parameters

    aPoint

    A point specifying a location in the coordinate system of layer.

    layer

    The layer into whose coordinate system aPoint is to be converted. The receiver and layer must share a common parent layer. This parameter may be nil.

    Return Value

    The point converted to the coordinate system of layer.

    Discussion

    If you specify nil for the layer parameter, this method returns the original point.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func convertRect(_ aRect: CGRect, fromLayer layer: CALayer!) -> CGRect

    Objective-C

    - (CGRect)convertRect:(CGRect)aRect fromLayer:(CALayer *)layer

    Parameters

    aRect

    A point specifying a location in the coordinate system of layer.

    layer

    The layer with aRect in its coordinate system. The receiver and layer and must share a common parent layer. This parameter may be nil.

    Return Value

    The rectangle converted to the receiver’s coordinate system.

    Discussion

    If you specify nil for the layer parameter, this method returns the original rect.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func convertRect(_ aRect: CGRect, toLayer layer: CALayer!) -> CGRect

    Objective-C

    - (CGRect)convertRect:(CGRect)aRect toLayer:(CALayer *)layer

    Parameters

    aRect

    A point specifying a location in the coordinate system of layer.

    layer

    The layer into whose coordinate system aRect is to be converted. The receiver and layer and must share a common parent layer. This parameter may be nil.

    Return Value

    The rectangle converted to the coordinate system of layer.

    Discussion

    If you specify nil for the layer parameter, this method returns the original rect.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func convertTime(_ timeInterval: CFTimeInterval, fromLayer layer: CALayer!) -> CFTimeInterval

    Objective-C

    - (CFTimeInterval)convertTime:(CFTimeInterval)timeInterval fromLayer:(CALayer *)layer

    Parameters

    timeInterval

    A point specifying a location in the coordinate system of layer.

    layer

    The layer with timeInterval in its time space. The receiver and layer and must share a common parent layer.

    Return Value

    The time interval converted to the receiver’s time space.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func convertTime(_ timeInterval: CFTimeInterval, toLayer layer: CALayer!) -> CFTimeInterval

    Objective-C

    - (CFTimeInterval)convertTime:(CFTimeInterval)timeInterval toLayer:(CALayer *)layer

    Parameters

    timeInterval

    A point specifying a location in the coordinate system of layer.

    layer

    The layer into whose time space timeInterval is to be converted. The receiver and layer and must share a common parent layer.

    Return Value

    The time interval converted to the time space of layer.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func hitTest(_ thePoint: CGPoint) -> CALayer!

    Objective-C

    - (CALayer *)hitTest:(CGPoint)thePoint

    Parameters

    thePoint

    A point in the coordinate system of the receiver's superlayer.

    Return Value

    The layer that contains thePoint or nil if the point lies outside the receiver’s bounds rectangle.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • Returns whether the receiver contains a specified point.

    Declaration

    Swift

    func containsPoint(_ thePoint: CGPoint) -> Bool

    Objective-C

    - (BOOL)containsPoint:(CGPoint)thePoint

    Parameters

    thePoint

    A point in the receiver’s coordinate system.

    Return Value

    YEStrue if the bounds of the layer contains the point.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • The visible region of the layer in its own coordinate space. (read-only)

    Declaration

    Swift

    var visibleRect: CGRect { get }

    Objective-C

    @property(readonly) CGRect visibleRect

    Discussion

    The visible region is the area not clipped by the containing scroll layer.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func scrollPoint(_ thePoint: CGPoint)

    Objective-C

    - (void)scrollPoint:(CGPoint)thePoint

    Parameters

    thePoint

    The point in the current layer that should be scrolled into position.

    Discussion

    If the layer is not contained by a CAScrollLayer object, this method does nothing.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func scrollRectToVisible(_ theRect: CGRect)

    Objective-C

    - (void)scrollRectToVisible:(CGRect)theRect

    Parameters

    theRect

    The rectangle to be made visible.

    Discussion

    If the layer is not contained by a CAScrollLayer object, this method does nothing.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • name name Property

    The name of the receiver.

    Declaration

    Swift

    var name: String!

    Objective-C

    @property(copy) NSString *name

    Discussion

    The layer name is used by some layout managers to identify a layer. The default value of this property is nil.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func shouldArchiveValueForKey(_ key: String!) -> Bool

    Objective-C

    - (BOOL)shouldArchiveValueForKey:(NSString *)key

    Parameters

    key

    The name of one of the receiver’s properties.

    Return Value

    YEStrue if the specified property should be archived or NOfalse if it should not.

    Discussion

    The default implementation returns YEStrue.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • Specifies the default value associated with the specified key.

    Declaration

    Swift

    class func defaultValueForKey(_ key: String!) -> AnyObject!

    Objective-C

    + (id)defaultValueForKey:(NSString *)key

    Parameters

    key

    The name of one of the receiver’s properties.

    Return Value

    The default value for the named property. Returns nil if no default value has been set.

    Discussion

    If you define custom properties for a layer but do not set a value, this method returns a suitable “zero” default value based on the expected value of the key. For example, if the value for key is a CGSize struct, the method returns a size struct containing (0.0,0.0) wrapped in an NSValue object. For a CGRect an empty rectangle is returned. For CGAffineTransform and CATransform3D, the appropriate identity matrix is returned.

    Special Considerations

    If key is not a known for property of the class, the result of the method is undefined.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • These constants are used by the autoresizingMask property.

    Declaration

    Swift

    struct CAAutoresizingMask : RawOptionSetType { init(_ rawValue: UInt32) init(rawValue rawValue: UInt32) static var LayerNotSizable: CAAutoresizingMask { get } static var LayerMinXMargin: CAAutoresizingMask { get } static var LayerWidthSizable: CAAutoresizingMask { get } static var LayerMaxXMargin: CAAutoresizingMask { get } static var LayerMinYMargin: CAAutoresizingMask { get } static var LayerHeightSizable: CAAutoresizingMask { get } static var LayerMaxYMargin: CAAutoresizingMask { get } }

    Objective-C

    enum CAAutoresizingMask { kCALayerNotSizable = 0, kCALayerMinXMargin = 1U << 0, kCALayerWidthSizable = 1U << 1, kCALayerMaxXMargin = 1U << 2, kCALayerMinYMargin = 1U << 3, kCALayerHeightSizable = 1U << 4, kCALayerMaxYMargin = 1U << 5 };

    Constants

    • LayerNotSizable

      kCALayerNotSizable

      The receiver cannot be resized.

      Available in OS X v10.5 and later.

    • LayerMinXMargin

      kCALayerMinXMargin

      The left margin between the receiver and its superview is flexible.

      Available in OS X v10.5 and later.

    • LayerWidthSizable

      kCALayerWidthSizable

      The receiver’s width is flexible.

      Available in OS X v10.5 and later.

    • LayerMaxXMargin

      kCALayerMaxXMargin

      The right margin between the receiver and its superview is flexible.

      Available in OS X v10.5 and later.

    • LayerMinYMargin

      kCALayerMinYMargin

      The bottom margin between the receiver and its superview is flexible.

      Available in OS X v10.5 and later.

    • LayerHeightSizable

      kCALayerHeightSizable

      The receiver’s height is flexible.

      Available in OS X v10.5 and later.

    • LayerMaxYMargin

      kCALayerMaxYMargin

      The top margin between the receiver and its superview is flexible.

      Available in OS X v10.5 and later.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • These constants are the predefined action identifiers used by actionForKey:, addAnimation:forKey:, defaultActionForKey:, removeAnimationForKey:, Accessing the Layer’s Filters, and the CAAction protocol method runActionForKey:object:arguments:.

    Declaration

    Swift

    let kCAOnOrderIn: NSString! let kCAOnOrderOut: NSString! let kCATransition: NSString!

    Objective-C

    NSString * const kCAOnOrderIn; NSString * const kCAOnOrderOut; NSString * const kCATransition;

    Constants

    • kCAOnOrderIn

      kCAOnOrderIn

      The identifier that represents the action taken when a layer becomes visible, either as a result being inserted into the visible layer hierarchy or the layer is no longer set as hidden.

      Available in OS X v10.5 and later.

    • kCAOnOrderOut

      kCAOnOrderOut

      The identifier that represents the action taken when the layer is removed from the layer hierarchy or is hidden.

      Available in OS X v10.5 and later.

    • kCATransition

      kCATransition

      The identifier that represents a transition animation.

      Available in OS X v10.5 and later.

  • This mask is used by the edgeAntialiasingMask property.

    Declaration

    Swift

    struct CAEdgeAntialiasingMask : RawOptionSetType { init(_ rawValue: UInt32) init(rawValue rawValue: UInt32) static var LayerLeftEdge: CAEdgeAntialiasingMask { get } static var LayerRightEdge: CAEdgeAntialiasingMask { get } static var LayerBottomEdge: CAEdgeAntialiasingMask { get } static var LayerTopEdge: CAEdgeAntialiasingMask { get } }

    Objective-C

    enum CAEdgeAntialiasingMask { kCALayerLeftEdge = 1U << 0, kCALayerRightEdge = 1U << 1, kCALayerBottomEdge = 1U << 2, kCALayerTopEdge = 1U << 3, };

    Constants

    • LayerLeftEdge

      kCALayerLeftEdge

      Specifies that the left edge of the receiver’s content should be antialiased.

      Available in OS X v10.5 and later.

    • LayerRightEdge

      kCALayerRightEdge

      Specifies that the right edge of the receiver’s content should be antialiased.

      Available in OS X v10.5 and later.

    • LayerBottomEdge

      kCALayerBottomEdge

      Specifies that the bottom edge of the receiver’s content should be antialiased.

      Available in OS X v10.5 and later.

    • LayerTopEdge

      kCALayerTopEdge

      Specifies that the top edge of the receiver’s content should be antialiased.

      Available in OS X v10.5 and later.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • The contents gravity constants specify the position of the content object when the layer bounds is larger than the bounds of the content object. The are used by the contentsGravity property.

    Declaration

    Swift

    let kCAGravityCenter: NSString! let kCAGravityTop: NSString! let kCAGravityBottom: NSString! let kCAGravityLeft: NSString! let kCAGravityRight: NSString! let kCAGravityTopLeft: NSString! let kCAGravityTopRight: NSString! let kCAGravityBottomLeft: NSString! let kCAGravityBottomRight: NSString! let kCAGravityResize: NSString! let kCAGravityResizeAspect: NSString! let kCAGravityResizeAspectFill: NSString!

    Objective-C

    NSString * const kCAGravityCenter; NSString * const kCAGravityTop; NSString * const kCAGravityBottom; NSString * const kCAGravityLeft; NSString * const kCAGravityRight; NSString * const kCAGravityTopLeft; NSString * const kCAGravityTopRight; NSString * const kCAGravityBottomLeft; NSString * const kCAGravityBottomRight; NSString * const kCAGravityResize; NSString * const kCAGravityResizeAspect; NSString * const kCAGravityResizeAspectFill;

    Constants

    • kCAGravityCenter

      kCAGravityCenter

      The content is horizontally and vertically centered in the bounds rectangle.

      Available in OS X v10.5 and later.

    • kCAGravityTop

      kCAGravityTop

      The content is horizontally centered at the top-edge of the bounds rectangle.

      Available in OS X v10.5 and later.

    • kCAGravityBottom

      kCAGravityBottom

      The content is horizontally centered at the bottom-edge of the bounds rectangle.

      Available in OS X v10.5 and later.

    • kCAGravityLeft

      kCAGravityLeft

      The content is vertically centered at the left-edge of the bounds rectangle.

      Available in OS X v10.5 and later.

    • kCAGravityRight

      kCAGravityRight

      The content is vertically centered at the right-edge of the bounds rectangle.

      Available in OS X v10.5 and later.

    • kCAGravityTopLeft

      kCAGravityTopLeft

      The content is positioned in the top-left corner of the bounds rectangle.

      Available in OS X v10.5 and later.

    • kCAGravityTopRight

      kCAGravityTopRight

      The content is positioned in the top-right corner of the bounds rectangle.

      Available in OS X v10.5 and later.

    • kCAGravityBottomLeft

      kCAGravityBottomLeft

      The content is positioned in the bottom-left corner of the bounds rectangle.

      Available in OS X v10.5 and later.

    • kCAGravityBottomRight

      kCAGravityBottomRight

      The content is positioned in the bottom-right corner of the bounds rectangle.

      Available in OS X v10.5 and later.

    • kCAGravityResize

      kCAGravityResize

      The content is resized to fit the entire bounds rectangle.

      Available in OS X v10.5 and later.

    • kCAGravityResizeAspect

      kCAGravityResizeAspect

      The content is resized to fit the bounds rectangle, preserving the aspect of the content. If the content does not completely fill the bounds rectangle, the content is centered in the partial axis.

      Available in OS X v10.5 and later.

    • kCAGravityResizeAspectFill

      kCAGravityResizeAspectFill

      The content is resized to completely fill the bounds rectangle, while still preserving the aspect of the content. The content is centered in the axis it exceeds.

      Available in OS X v10.5 and later.

  • Defines the identity transform matrix used by Core Animation.

    Declaration

    Swift

    let CATransform3DIdentity: CATransform3D

    Objective-C

    const CATransform3D CATransform3DIdentity

    Constants

    • CATransform3DIdentity

      CATransform3DIdentity

      The identity transform: [1 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 1].

      Available in OS X v10.5 and later.

  • These constants specify the scaling filters used by magnificationFilter and minificationFilter.

    Declaration

    Swift

    let kCAFilterLinear: NSString! let kCAFilterNearest: NSString! let kCAFilterTrilinear: NSString!

    Objective-C

    NSString * const kCAFilterLinear; NSString * const kCAFilterNearest; NSString * const kCAFilterTrilinear;

    Constants

    • kCAFilterLinear

      kCAFilterLinear

      Linear interpolation filter.

      Available in OS X v10.5 and later.

    • kCAFilterNearest

      kCAFilterNearest

      Nearest neighbor interpolation filter.

      Available in OS X v10.5 and later.

    • kCAFilterTrilinear

      kCAFilterTrilinear

      Trilinear minification filter. Enables mipmap generation. Some renderers may ignore this, or impose additional restrictions, such as source images requiring power-of-two dimensions..

      Available in OS X v10.6 and later.