7

我有一个围绕路径制作动画的球图像。动画设置为永远重复,但为什么重复之间会有延迟?

这是我的代码:

CGPathRef aPath;
aPath = CGPathCreateWithEllipseInRect(CGRectMake(0, 0, SIZE, SIZE), NULL);

[CATransaction begin];

arcAnimation = [CAKeyframeAnimation animationWithKeyPath: @"position"];
[arcAnimation setBeginTime:CACurrentMediaTime()];
[arcAnimation setDuration: 1.5];
[arcAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
[arcAnimation setAutoreverses: NO];
[arcAnimation setRepeatCount:HUGE_VALF];
arcAnimation.removedOnCompletion = NO;
arcAnimation.fillMode = kCAFillModeRemoved;
[arcAnimation setPath: aPath];
[ball.layer addAnimation: arcAnimation forKey: @"position"];
[CATransaction commit];
CFRelease(aPath);
4

3 回答 3

11

尝试这个:

[animation setCalculationMode:kCAAnimationPaced]
于 2013-02-18T13:39:02.087 回答
1

我不知道实际的答案,但你在这里做了很多不必要的事情,我的建议是你先删除它。不需要 CATransaction 块(begincommit)。没有必要为setBeginTime:. 绝对不需要设置removedOnCompletionand fillMode,因为这不是分组动画。只需将动画添加到图层并退后即可。它会立即开始并永远重复,你的代码会更简单更好。

于 2013-02-01T18:47:03.767 回答
0

您必须替换kCAFillModeRemovedkCAFillModeForwards或其他值。阅读有关原因的文档。

此外:

代替:

[arcAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]]

使用(取决于您的测试结果):

[arcAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]]

或者

[arcAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]]
于 2013-02-01T18:46:16.513 回答