Created
October 20, 2011 11:52
-
-
Save 7gano/1300959 to your computer and use it in GitHub Desktop.
CAKeyframeAnimation.rotationMode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
self.view.backgroundColor = [UIColor blackColor]; | |
[self action]; | |
} | |
- (void)action | |
{ | |
//Create Content Layer | |
CALayer* layer = [CALayer layer]; | |
layer.frame = CGRectMake(0, 0, 150, 150); | |
UIImage* image = [UIImage imageNamed:@"Sgt600.jpg"]; | |
layer.contents = (id)image.CGImage; | |
[self.view.layer addSublayer:layer]; | |
CAKeyframeAnimation* animation; | |
animation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; | |
animation.duration = 3.0; | |
animation.repeatCount = FLT_MAX; | |
//Create circle path | |
CGMutablePathRef path = CGPathCreateMutable(); | |
CGPathAddArc(path, | |
NULL, | |
self.view.center.x, | |
self.view.center.y, | |
100, | |
0, | |
M_PI * 2, false); | |
animation.path = path; | |
animation.rotationMode = kCAAnimationRotateAuto; | |
[layer addAnimation:animation forKey:nil]; | |
CFRelease(path); | |
} |
CGPathCreateWithEllipseInRectで簡単にやりたいところだけど、これでPath作ると、終点が長くなるみたいで、そこでアニメーションがかなりの時間止まってしまう。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
kCAAnimationRotateAutoReverseにすると、アニメーションするLayerの上下が逆になる。