ios - 如何使用CAKeyFrameAnimation向后制作图像动画

标签 ios objective-c cakeyframeanimation

我是iOS开发的新手。我正在创建用于旋转图像的关键帧动画。图像已成功向前旋转。我想向后完整旋转图像。

这是我的代码。

UIImageView *tempView = [[UIImageView alloc] initWithFrame:CGRectMake(28,158,133,133)];
tempView.image = [UIImage imageNamed:@"1_03.png"];
[self.view addSubview:tempView];

const NSUInteger rotations = 1;
const NSTimeInterval duration  = 4.0f;

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.delegate = self;
anim.repeatCount = INFINITY;
[tempView.layer addAnimation:anim forKey:@"animation"];

tempView.transform = CGAffineTransformMakeRotation(touchUpStartAngle +     (touchUpEndAngle));

这个怎么做。

最佳答案

尝试这个。

UIImageView *tempView = [[UIImageView alloc] initWithFrame:CGRectMake(28,158,133,133)];
tempView.image = [UIImage imageNamed:@"1_03.png"];
[self.view addSubview:tempView];

const NSUInteger rotations = 1;
const NSTimeInterval duration  = 4.0f;

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.delegate = self;
anim.repeatCount = INFINITY;
[tempView.layer addAnimation:anim forKey:@"animation"];

tempView.transform = CGAffineTransformMakeRotation(touchUpStartAngle +     (touchUpEndAngle));

关于ios - 如何使用CAKeyFrameAnimation向后制作图像动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17207240/

相关文章:

IOS swiftUI 无法从本地文件读取json

ios - 自定义 PageControl 图像 - Swift

ios - `indexOf` 抛出 "Object type does not match RLMResults"异常

objective-c - EXC_BAD_ACCESS 调用 block

ios - 如何从单个文本文件中提取不同语言的日期?

ios - 检测动画 UIImageView 上的点击

ios - 苹果拒绝了我的应用:性能-应用完整性

iphone - 当键盘覆盖事件的 UITextField 时 UIScrollView 不滚动(使用苹果的例子)

ios - 曲线动画的旋转方向?

ios - 处理 CAKeyFrameAnimation 的正确方法