CALayerDelegate Informal Protocol Reference

Framework
/System/Library/Frameworks/QuartzCore.framework
Declared in
CALayer.h
Companion guides

Overview

The CALayerDelegate informal protocol is implemented by the layer’s delegate to respond to layer-related events. You can implement the methods of this protocol to provide the layer’s content, handle the layout of sublayers, and provide custom animation actions to perform. The object that implements this protocol must be assigned to the delegate property of the layer object.

Tasks

Providing the Layer’s Content

Laying Out Sublayers

Providing a Layer’s Actions

Instance Methods

actionForLayer:forKey:

Asks the delegate for the specified action. (required)

- (id < CAAction >)actionForLayer:(CALayer *)layer forKey:(NSString *)key
Parameters
layer

The layer that is the target of the action.

key

The identifier of the action.

Return Value

An object implementing the CAAction protocol or nil if the delegate does not specify a behavior for the specified key.

Discussion

Your delegate object can implement this method when it wants to provide custom actions for a layer. For information about how layer-related actions are chosen, see the actionForKey: method of CALayer.

Availability
  • Available in iOS 2.0 and later.
Declared In
CALayer.h

displayLayer:

Asks the delegate to update the layer’s contents. (required)

- (void)displayLayer:(CALayer *)layer
Parameters
layer

The layer whose contents need updating.

Discussion

The layer calls this method early in its update cycle to give your delegate a chance to set the layer’s contents property directly. If you do not implement this method, the layer calls the drawLayer:inContext: method instead.

Availability
  • Available in iOS 2.0 and later.
Declared In
CALayer.h

drawLayer:inContext:

Asks the delegate to draw the layer’s contents. (required)

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
Parameters
layer

The layer whose contents need to be drawn.

ctx

The graphics context to use for drawing. The graphics context incorporates the appropriate scale factor for drawing to the target screen.

Discussion

If you do not want to set the contents of the layer directly using the displayLayer: method, you can implement this method and use it to draw the contents of your layer. You might prefer this method in cases where the layer’s content is already dynamic and must be regenerated.

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

Availability
  • Available in iOS 2.0 and later.
Declared In
CALayer.h

layoutSublayersOfLayer:

Asks the delegate to lay out the sublayers of the specified layer.

- (void)layoutSublayersOfLayer:(CALayer *)layer
Parameters
layer

The layer that requires layout of its sublayers.

Discussion

During a layout update, the layer calls this method to give your delegate a chance to adjust the position or size of any sublayers. Your delegate object is responsible for changing the frame of each sublayer that requires layout.

If you do not implement this method, the layer calls the layoutSublayersOfLayer: method on the object in the layer’s layoutManager property. If you do implement this method, the layer does not ask its layout manager object to update the layout.

Availability
  • Available in iOS 3.0 and later.
Declared In
CALayer.h