Class CALayer

CPObject
    extended byCALayer
Direct Known Subclasses:
CAFlashLayer

@implementation CALayer : CPObject

A CALayer is similar to a CPView, but with the ability to have a transform applied to it.


Method Summary
+(CALayer)layer
          Returns a new animation layer.
-(id)init
          Initializes the animation layer.
-(void)addSublayer:(CALayer)aLayer
          Adds the specified layer as a sublayer of the receiver.
-(CGAffineTransform)affineTransform
          Returns the layer's affine transform.
-(CGPoint)anchorPoint
          Returns the layer's anchor point.
-(CPColor)backgroundColor
          Returns the layer's background color.
-(CGRect)backingStoreFrame
          The Backing Store Frame specifies the frame of the actual backing store used to contain this layer.
-(CGRect)bounds
          Returns the layer's bound.
-(BOOL)containsPoint:(CGPoint)aPoint
          Returns YES if the layer contains the point.
-(CGImage)contents
          Returns the CGImage contents of this layer.
-(CGPoint)convertPoint:(CGPoint)aPoint fromLayer:(CALayer)aLayer
          Converts the point from the specified layer's coordinate system into the receiver's coordinate system.
-(CGPoint)convertPoint:(CGPoint)aPoint toLayer:(CALayer)aLayer
          Converts the point from the receiver's coordinate system to the specified layer's coordinate system.
-(CGRect)convertRect:(CGRect)aRect fromLayer:(CALayer)aLayer
          Converts the rectangle from the specified layer's coordinate system to the receiver's coordinate system.
-(CGRect)convertRect:(CGRect)aRect toLayer:(CALayer)aLayer
          Converts the rectangle from the receier's coordinate system to the specified layer's coordinate system.
-(id)delegate
          Returns the layer's delegate.
-(void)display
          Displays the contents of this layer.
-(void)drawInContext:(CGContext)aContext
          Draws this layer's contents into the specified context.
-(CGRect)frame
          Returns the layer's frame.
-(BOOL)hidden
          Returns YES if the layer is hidden.
-(CALayer)hitTest:(CGPoint)aPoint
          Returns the farthest descendant of this layer that contains the specified point.
-(void)insertSublayer:(CALayer)aLayer above:(CALayer)aSublayer
          Inserts a layer above another layer.
-(void)insertSublayer:(CALayer)aLayer atIndex:(unsigned)anIndex
          Inserts the specified layer as a sublayer into the specified index.
-(void)insertSublayer:(CALayer)aLayer below:(CALayer)aSublayer
          Inserts a layer below another layer.
-(BOOL)isHidden
          Returns YES if the layer is hidden.
-(BOOL)needsDisplayOnBoundsChange
          Returns YES if the display should be redrawn on a bounds change.
-(float)opacity
          Returns the opacity of the layer.
-(CGPoint)position
          Returns the layer's position.
-(void)removeFromSuperlayer
          Removes the receiver from its superlayer.
-(void)replaceSublayer:(CALayer)aSublayer with:(CALayer)aLayer
          Replaces a sublayer.
-(void)setAffineTransform:(CGAffineTransform)anAffineTransform
          Sets the affine transform applied to this layer.
-(void)setAnchorPoint:(CGPoint)anAnchorPoint
          Sets the layer's anchor point.
-(void)setBackgroundColor:(CPColor)aColor
          Sets the layer's background color.
-(void)setBackingStoreFrame:(CGRect)aFrame
          Sets the frame's backing store.
-(void)setBounds:(CGRect)aBounds
          Sets the bounds (origin and size) of the rectangle.
-(void)setContents:(CGImage)contents
          Sets the image contents of this layer.
-(void)setDelegate:(id)aDelegate
          Sets the delegate for this layer.
-(void)setFrame:(CGRect)aFrame
          Sets the frame of the layer.
-(void)setHidden:(BOOL)isHidden
          Sets whether the layer is hidden.
-(void)setMasksToBounds:(BOOL)masksToBounds
          Sets whether content that goes lies outside the bounds is hidden or visible.
-(void)setNeedsDisplay
          Marks the layer as needing to be redrawn.
-(void)setNeedsDisplayInRect:(CGRect)aRect
          Marks the specified rectange as needing to be redrawn.
-(void)setNeedsDisplayOnBoundsChange:(BOOL)needsDisplayOnBoundsChange
          Sets whether the layer needs to be redrawn when its bounds are changed.
-(void)setOpacity:(float)anOpacity
          Sets the opacity for the layer.
-(void)setPosition:(CGPoint)aPosition
          Sets the layer's position.
-(void)setSublayerTransform:(CGAffineTransform)anAffineTransform
          Sets the affine transform that gets applied to all the sublayers.
-(void)setZPosition:(int)aZPosition
          Sets the layer's z-ordering.
-(CGAffineTransform)sublayerTransform
          Returns the affine transform applied to the sublayers.
-(CPArray)sublayers
          Returns an array of the receiver's sublayers.
-(CALayer)superlayer
          Returns the receiver's superlayer.

Methods inherited from class CPObject
initialize, alloc, class, instanceMethodForSelector, instancesRespondToSelector, isSubclassOfClass, load, new, setVersion, superclass, version, init, autorelease, awakeAfterUsingCoder, class, classForCoder, classForKeyedArchiver, className, copy, dealloc, description, doesNotRecognizeSelector, forwardInvocation, hash, isEqual, isKindOfClass, isMemberOfClass, isProxy, methodForSelector, methodSignatureForSelector, mutableCopy, performSelector, performSelector, performSelector, release, replacementObjectForArchiver, replacementObjectForCoder, replacementObjectForKeyedArchiver, respondsToSelector, retain, self, superclass

Delegate Method Summary
-(void)drawLayer:(CALayer)layer inContext:(CGContextRef)ctx
          If the delegate implements this method, the CALayer will call this in place of its drawInContext:.
-(void)displayLayer:(CALayer)layer
          The delegate can override the layer's display method by implementing this method.


Method Detail

layer

+(CALayer)layer
Returns a new animation layer.

init

-(id)init
Initializes the animation layer.

addSublayer

-(void)addSublayer:(CALayer)aLayer
Adds the specified layer as a sublayer of the receiver.
Parameters:
aLayer

affineTransform

-(CGAffineTransform)affineTransform
Returns the layer's affine transform.

anchorPoint

-(CGPoint)anchorPoint
Returns the layer's anchor point.

backgroundColor

-(CPColor)backgroundColor
Returns the layer's background color.

backingStoreFrame

-(CGRect)backingStoreFrame
The Backing Store Frame specifies the frame of the actual backing store used to contain this layer. Naturally, by default it is the same as the frame, however, users can specify their own custom Backing Store Frame in order to speed up certain operations, such as live transformation.
Returns:
the backing store frame

bounds

-(CGRect)bounds
Returns the layer's bound.

containsPoint

-(BOOL)containsPoint:(CGPoint)aPoint
Returns YES if the layer contains the point.
Parameters:
aPoint - the point to test

contents

-(CGImage)contents
Returns the CGImage contents of this layer. The default contents are nil.

convertPoint

-(CGPoint)convertPoint:(CGPoint)aPoint fromLayer:(CALayer)aLayer
Converts the point from the specified layer's coordinate system into the receiver's coordinate system.
Parameters:
aPoint - the point to convert
aLayer - the layer coordinate system to convert from
Returns:
the converted point

convertPoint

-(CGPoint)convertPoint:(CGPoint)aPoint toLayer:(CALayer)aLayer
Converts the point from the receiver's coordinate system to the specified layer's coordinate system.
Parameters:
aPoint - the point to convert
aLayer - the layer coordinate system to convert to
Returns:
the converted point

convertRect

-(CGRect)convertRect:(CGRect)aRect fromLayer:(CALayer)aLayer
Converts the rectangle from the specified layer's coordinate system to the receiver's coordinate system.
Parameters:
aRect - the rectangle to convert
aLayer - the layer coordinate system to convert from
Returns:
the converted rectangle

convertRect

-(CGRect)convertRect:(CGRect)aRect toLayer:(CALayer)aLayer
Converts the rectangle from the receier's coordinate system to the specified layer's coordinate system.
Parameters:
aRect - the rectange to convert
aLayer - the layer coordinate system to convert to
Returns:
the converted rectangle

delegate

-(id)delegate
Returns the layer's delegate

display

-(void)display
Displays the contents of this layer.

drawInContext

-(void)drawInContext:(CGContext)aContext
Draws this layer's contents into the specified context.
Parameters:
aContext - the context to draw the layer into

frame

-(CGRect)frame
Returns the layer's frame. The frame defines the bounding box of the layer: the smallest possible rectangle that could fit this layer after transform properties are applied in superlayer coordinates.

hidden

-(BOOL)hidden
Returns YES if the layer is hidden.

hitTest

-(CALayer)hitTest:(CGPoint)aPoint
Returns the farthest descendant of this layer that contains the specified point.
Parameters:
aPoint - the point to test
Returns:
the containing layer or nil if there was no hit.

insertSublayer

-(void)insertSublayer:(CALayer)aLayer above:(CALayer)aSublayer
Inserts a layer above another layer.
Parameters:
aLayer - the layer to insert
aSublayer - the layer to insert above
Throws:
CALayerNotFoundException - if aSublayer is not in the array of sublayers

insertSublayer

-(void)insertSublayer:(CALayer)aLayer atIndex:(unsigned)anIndex
Inserts the specified layer as a sublayer into the specified index.
Parameters:
aLayer - the layer to insert
anIndex - the index to insert the layer at

insertSublayer

-(void)insertSublayer:(CALayer)aLayer below:(CALayer)aSublayer
Inserts a layer below another layer.
Parameters:
aLayer - the layer to insert
aSublayer - the layer to insert below
Throws:
CALayerNotFoundException - if aSublayer is not in the array of sublayers

isHidden

-(BOOL)isHidden
Returns YES if the layer is hidden.

needsDisplayOnBoundsChange

-(BOOL)needsDisplayOnBoundsChange
Returns YES if the display should be redrawn on a bounds change.

opacity

-(float)opacity
Returns the opacity of the layer. The value is between 0.0 (transparent) and 1.0 (opaque).

position

-(CGPoint)position
Returns the layer's position

removeFromSuperlayer

-(void)removeFromSuperlayer
Removes the receiver from its superlayer.

replaceSublayer

-(void)replaceSublayer:(CALayer)aSublayer with:(CALayer)aLayer
Replaces a sublayer.
Parameters:
aSublayer - the layer to insert
aLayer - the layer to replace

setAffineTransform

-(void)setAffineTransform:(CGAffineTransform)anAffineTransform
Sets the affine transform applied to this layer.
Parameters:
anAffineTransform - the new affine transform

setAnchorPoint

-(void)setAnchorPoint:(CGPoint)anAnchorPoint
Sets the layer's anchor point. The default point is [0.5, 0.5].
Parameters:
anAnchorPoint - the layer's new anchor point

setBackgroundColor

-(void)setBackgroundColor:(CPColor)aColor
Sets the layer's background color.
Parameters:
aColor - the new background color

setBackingStoreFrame

-(void)setBackingStoreFrame:(CGRect)aFrame
Sets the frame's backing store.
Parameters:
aFrame - the new backing store.

setBounds

-(void)setBounds:(CGRect)aBounds
Sets the bounds (origin and size) of the rectangle.
Parameters:
aBounds - the new bounds for the layer

setContents

-(void)setContents:(CGImage)contents
Sets the image contents of this layer.
Parameters:
contents - the image to display

setDelegate

-(void)setDelegate:(id)aDelegate
Sets the delegate for this layer.
Parameters:
aDelegate - the delegate

setFrame

-(void)setFrame:(CGRect)aFrame
Sets the frame of the layer. The frame defines a bounding rectangle in the superlayer's coordinate system.
Parameters:
aFrame - the new frame rectangle

setHidden

-(void)setHidden:(BOOL)isHidden
Sets whether the layer is hidden.
Parameters:
isHidden - YES means the layer will be hidden. NO means the layer will be visible.

setMasksToBounds

-(void)setMasksToBounds:(BOOL)masksToBounds
Sets whether content that goes lies outside the bounds is hidden or visible.
Parameters:
masksToBounds - YES hides the excess content. NO makes it visible.

setNeedsDisplay

-(void)setNeedsDisplay
Marks the layer as needing to be redrawn.

setNeedsDisplayInRect

-(void)setNeedsDisplayInRect:(CGRect)aRect
Marks the specified rectange as needing to be redrawn.
Parameters:
aRect - the area that needs to be redrawn.

setNeedsDisplayOnBoundsChange

-(void)setNeedsDisplayOnBoundsChange:(BOOL)needsDisplayOnBoundsChange
Sets whether the layer needs to be redrawn when its bounds are changed.
Parameters:
needsDisplayOnBoundsChange - YES means the display is redraw on a bounds change.

setOpacity

-(void)setOpacity:(float)anOpacity
Sets the opacity for the layer.
Parameters:
anOpacity - the new opacity (between 0.0 (transparent) and 1.0 (opaque)).

setPosition

-(void)setPosition:(CGPoint)aPosition
Sets the layer's position.
Parameters:
aPosition - the layer's new position

setSublayerTransform

-(void)setSublayerTransform:(CGAffineTransform)anAffineTransform
Sets the affine transform that gets applied to all the sublayers.
Parameters:
anAffineTransform - the transform to apply to sublayers

setZPosition

-(void)setZPosition:(int)aZPosition
Sets the layer's z-ordering.
Parameters:
aZPosition - the layer's new z-ordering

sublayerTransform

-(CGAffineTransform)sublayerTransform
Returns the affine transform applied to the sublayers.

sublayers

-(CPArray)sublayers
Returns an array of the receiver's sublayers.

superlayer

-(CALayer)superlayer
Returns the receiver's superlayer.

Delegate Method Detail

drawLayer

-(void)drawLayer:(CALayer)layer inContext:(CGContextRef)ctx
If the delegate implements this method, the CALayer will call this in place of its drawInContext:.
Parameters:
layer - the layer to draw for
ctx - the context to draw on

displayLayer

-(void)displayLayer:(CALayer)layer
The delegate can override the layer's display method by implementing this method.
Parameters:
layer

Created on Sat Sep 13 14:15:43 PDT 2008