1

我正在实施动画项目。我有一个图像 wheel.png。如何使用 CAKeyFrameAnimation 旋转此图像。我已经使用 CABasicAnimation 旋转了此图像。

4

1 回答 1

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));
于 2013-06-19T13:39:32.310 回答