0

我需要为 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 从起点移动到终点可以,但之后移动到起点并从起点到终点重复动画。所以,从终点到起点没有动画。有可能吗?

4

2 回答 2

4

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

也就是说,如果它真的是一个无限动画,那么你不需要 thefillMode或 theremovedOnCompletion

于 2013-07-18T08:13:39.797 回答
0

我是你,我会简单地使用:

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

与选项

UIViewAnimationOptionRepeat

于 2013-07-18T08:12:50.693 回答