Contenu connexe Similaire à Core animation (20) Plus de Weizhong Yang (20) Core animation1. CoreAnimation
Weizhong Yang
a.k.a zonble
zonble@gmail.com
http://zonble.net
11. CALayer
• iOS
• UIView layer [aView
layer] or aView.layer
• Mac
• NSView setWantsLayer:
• iOS
12. CALayer Interface
• frame bounds background color
• layer layer
addSublayer
• superlayer
13. CALayer View
• responder
event Click Touch…
• property
•
14. CALayer
• CALayer *aLayer = [CALayer layer];
• aLayer.contents = (id)[UIImage
imageNamed:@”test.jpg”].CGImage;
• fade in/
out
16. • Layer property
• CAAnimation
• …
19. CATransition…
CATransition *t = [CATransition animation];
t.type = kCATransitionMoveIn
t.subtype = kCATransitionFromRight;
aLayer.contents = (id)[UIImage
imageNamed:@”test.jpg”].CGImage;
[aLayer addAnimation:t forKey:@"Transition"];
//
24. CABasicAnimation
•
• @”transform.rotation.x”
• @”transform.rotation.y”
• @”transform.rotation.z”
• ...
26. CAKeyframeAnimation
• fromValue toValue
CGPathRef
• CAKeyframeAnimation *a
=[CAKeyframeAnimation
animationWithKeyPath:@"position"];
• a.path = (CGPathRef)path;
29. fill mode
• layer
• animation.fillMode =
kCAFillModeForwards;
• …
30. CABasicAnimation *a = [CABasicAnimation
animationWithKeyPath:@”bounds”];
a.fromValue = [NSValue valuwWithCGRect:fromRect];
a.toValue = [NSValue valuwWithCGRect:toRect];
[aLayer addAnimation:a forKey:@"boundsAnimation"];
NSLog(@”bounds:%@”, NSStringFromCGRect(aLayer.bounds));
• bounds toValue
• layer layer property
33. • [self
perforeSelector:@selector(runAnimation1)
withObject:nil afterDelay:1.0]; //
• [self
perforeSelector:@selector(runAnimation2)
withObject:nil afterDelay:2.0]; //
•
36. animation.delegate = self;
[myLayer addAnimation: animation forKey:@”key”];
...
- (void)animationDidStop:(CAAnimation
*)theAnimation finished:(BOOL)flag {
// Fire another animation
}
//
38. λ λ
• CAAnimation
block …
• iOS 5
• Lion
41. contents
CALayer Quartz
- (void)drawInContext:(CGContextRef)ctx
{
UIGraphicsPushContext(ctx);
// ctx current graphics context :D
UIBezierPath *path = [UIBezierPath
bezierPathWithRoundedRect:self.bounds cornerRadius:10.0];
CGContextSaveGState(ctx);
CGContextAddPath(ctx, path.CGPath);
CGContextClip(ctx);
[image drawInRect:self.bounds];
CGContextRestoreGState(ctx);
UIGraphicsPopContext();
}
42. view layer
view
UIGraphicsBeginImageContext(self.bounds.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[self.layer renderInContext:ctx];
UIImage *anImage =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return anImage;
// :D
45. Accessibility
• app
• …
• UIView/UIControl
Accessibility CALayer
Accessibility
Notes de l'éditeur \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n