我正在实施动画项目。我有一个image wheel.png。如何使用CAKeyFrameAnimation旋转此图像。我已使用CABasicAnimation旋转此图像。
答案 0 :(得分:2)
以下是ray的网站上的教程,该网站逐步展示了如何创建旋转轮。检查示例代码以查看旋转动画。这可能就是你要找的东西。
http://www.raywenderlich.com/9864/how-to-create-a-rotating-wheel-control-with-uikit
虽然它使用了UIKit
,但你明白了。
编辑:
以下是使用CAKeyFrameAnimation
连续旋转图像的示例代码,您可以使用它来执行您喜欢的操作。希望这会帮助你。
UIImageView *tempView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 80, 80)];
tempView.image = [UIImage imageNamed:@"Icon"];
tempView.backgroundColor = [UIColor redColor];
[self.view addSubview:tempView];
const NSUInteger rotations = 10;
const NSTimeInterval duration = 5;
CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];
CGFloat touchUpStartAngle = 0;
CGFloat touchUpEndAngle = (M_PI);
CGFloat angularVelocity = (((2 * M_PI) * rotations) + M_PI) / duration;
anim.values = @[@(touchUpStartAngle), @(touchUpStartAngle + angularVelocity * duration)];
anim.duration = duration;
anim.autoreverses = NO;
anim.delegate = self;
anim.repeatCount = 1;
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[tempView.layer addAnimation:anim forKey:@"test"];
tempView.transform = CGAffineTransformMakeRotation(touchUpStartAngle + (touchUpEndAngle));