ios - CAKeyframeAnimation 从头到尾重复动画

标签 ios animation cakeyframeanimation

我需要为 UIImageView 添加从起点到终点以及之后从终点到起点的无限动画。 我正在尝试这样:

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.duration = 2.0;
pathAnimation.repeatCount = HUGE_VALF;
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

CGPoint endPoint = CGPointMake(320.0f - 30.0f, self.myImage.frame.size.height);
CGMutablePathRef curvedPath = CGPathCreateMutable();
CGPathMoveToPoint(curvedPath, NULL, self.myImage.frame.origin.x, self.myImage.frame.origin.y);
CGPathAddCurveToPoint(curvedPath, NULL, endPoint.x, self.myImage.frame.origin.y,
                      endPoint.x, self.myImage.frame.origin.y, endPoint.x, endPoint.y);
pathAnimation.path = curvedPath;
CGPathRelease(curvedPath);

[self.myImage.layer addAnimation:pathAnimation forKey:@"curveAnimation"];

myImage 可以从起点移动到终点,但之后移动到起点并从起点到终点重复动画。所以,从终点到起点没有动画。可以吗?

最佳答案

动画以与您来时相同的方式返回就像将 autoreverses 设置为 YES 一样简单。

也就是说,如果它真的是一个无限动画,那么您就不需要 fillModeremovedOnCompletion

关于ios - CAKeyframeAnimation 从头到尾重复动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17717929/

相关文章:

ios - 使用 CAKeyframeAnimation 延迟 UIView 的动画开始?

android - 应用内购买 : Share user In-App purchases between Android and iOS

ios:条件绑定(bind)的初始化程序必须具有可选类型,而不是 'LOTAnimationView'

ios - 关于在 Swift 中使 UIView 从屏幕上消失的问题

ios - UITextField 使用动画更改右 View 大小

ios - 对于大于 PI 的值,CAKeyFrameAnimation 不是线性的

ios - 如何使用 SWIFT 为特定用户安排不同的推送通知

ios - 在更新之间更改 AppID 前缀是否安全?

ios - 从另一个类访问一个类变量的值 - Objective-C

ios - 检测动画 UIImageView 上的点击