Skip to content

Instantly share code, notes, and snippets.

@7gano
Created October 20, 2011 11:52
Show Gist options
  • Save 7gano/1300959 to your computer and use it in GitHub Desktop.
Save 7gano/1300959 to your computer and use it in GitHub Desktop.
CAKeyframeAnimation.rotationMode
- (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);
}
@7gano
Copy link
Author

7gano commented Oct 20, 2011

kCAAnimationRotateAutoReverseにすると、アニメーションするLayerの上下が逆になる。

@7gano
Copy link
Author

7gano commented Oct 20, 2011

CGPathCreateWithEllipseInRectで簡単にやりたいところだけど、これでPath作ると、終点が長くなるみたいで、そこでアニメーションがかなりの時間止まってしまう。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment