Core animation classes
- Layer classes that provide content for display
- Animation and timing classes
- Layout and constraint classes
- A transaction class that groups multiple layer changes into an atomic update
Layer classes
CALayer is the parent class for all types of Core animation layers.
CALayer diverges from the application kit and cocoa touch view classes in that it's not necessary to subclass CALayer in order to display content.
Animation and Timing Classes
CAAnimation adopts CAMediaTiming protocol which provides the simple duration,speed and repeat count for an animation.
and adopts CAAction protocol.
- CATransition
- CAAnimationGroup
- CAPropertyAnimation
- CABasicAnimation
- CAKeyframeAnimation
Layout Manager Classes
- CAContraint
Transaction Management Classes
Core Animation Rendering Architecture
NSView,UIView are objects in the MVC pattern.
Core Animation Layers are model objects.
the actual display is not the layer's responsibility.
a presentation tree and a render tree.
layer-tree -> Presentation-tree -> Render-tree (Private)
Layer-tree Hierarchy
Displaying Layers in Views
[theView setLayer: theRootLayer];
[theView setWantsLayer:YES];
Adding,Removing Layers from a Hierarchy
while inserting,removing,replacing layers cause kCAOnOrderIn, kCAOnOrderOut, kCATransition triggered.
Repositioning and Resizing Layers
If a layer's needsDisplayOnBoundsChange property is YES, the layer's content is recached when the layer's bounds changes. this value is no by default.
Autoresizing Layers
CAAutoresizingMask
Clipping Sublayers
masksToBounds determines if sublayers are clipped to the parent.
Providing Layer Content
When using Cocoa views you must subclass NSVIew or UIView and implement drawRect: in order to display anything. However CALayer instances can often be used directly, without requiring subclassing. Because CALayer is a key-value coding compliant container class, that is you can store arbitrary values in any instance, subclassing can often be avoided entirely.
Providing CALayer Content
- Explicitly set the contents property of a layer instance using a CGImageRef that contains the content image.
- Specify a delegate that provides, or draws, the content.
- Subclass CALayer and override one of the display methods.
Setting the Contents Property
CALayer *theLayer;
theLayer = [CALayer layer];
theLayer.position = CGPointMake(50,50);
theLayer.bounds = CGRectMake(0,0,100,100);
theLayer.contents = theImage; //CGImageRef
Using a Delegate to Provide Content
displayLayer: or drawLayer:inContext: are called by sending it a setNeedsDisplay or setNeedsDisplayInRect: or needsDisplayOnBoundsChange = YES.
Subclassing is not required to store the state value, coz the CALayer instance acts as a key-value coding container.
- (void)displayLayer:(CALayer*)theLayer
{
if ([[theLayer valueForKey:@"state"] boolValue])
{
theLayer.contents = [someHelperObject loadStateYesImage];
}
else {
theLayer.contents = [someHelperObject loadStateNoImage];
}
}
if you must the layer's content rather than loading it from an image, use drawLayer:inContext:
- (void)drawLayer:(CALayer*)theLayer inContext:(CGContextRef)theContext
{
CGMutablePathRef thePath = CGPathCreateMutable();
CGPathMoveToPoint( thePath,NULL,15.0f,15.f);
CGPathAddCurveToPoint( thePath, NULL, 15.f,250.f,295.f,250.f,295.f,15.f );
CGContextBeginPath(theContext);
CGContextAddPath(theContext, thePath);
CGContextSetLineWidth( theContext, [[theLayer valueForKey:@"lineWidth"] floatValue]);
CGContextStokePath(theContext);
CFRelease(thePath);
}
Providing CALayer Content by Subclassing
using property rather than depending on the key-value coding container.
- (void)display{ if(self.state) { self.contents = [someHelperObject loadStateYesImage]; } else { self.contents = [someHelperObject loadStateNoImage]; }}
- (void)drawInContext:(CGContextRef)theContext{ CGMutablePathRef thePath = CGPathCreateMutable(); CGPathMoveToPoint(thePath,NULL,15.f,15.f); CGPathAddCurveToPoint(thePath,NULL,15.f,250.f,295.f,250.f,295.f,15.f); CGContextBeginPath(theContext); CGContextAddPath(theContext, thePath); CGContextSetLineWidth(theContext,self.lineWidth); CGContextSetStrokeColorWithColor(theContext, self.lineColor); CGContextStrokePath(theContext); CFRelease(thePath);}
Positioning Content Within a Layer
contentsGravity property allows you to position and scale the layer's contents image within the layer bounds. by default, the content image fills the layer's bounds entirely, ignoring the natural aspect ratio of the image.
댓글 없음:
댓글 쓰기