CAKeyframeAnimation从头到尾重复动画

时间:2013-07-18 08:04:02

标签: 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从开始点移动到结束ok,但在此之后移动到开始点并从开始点到结束重复动画。所以,从终点开始没有动画。有可能吗?

2 个答案:

答案 0 :(得分:4)

以与您相同的方式制作动画就像将autoreverses设置为YES一样简单。

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

答案 1 :(得分:0)

我是你,我只是使用:

[UIVIew animateWithDuration:delay:options:animations:completion:]

带有选项

UIViewAnimationOptionRepeat

相关问题