CAKeyFrame Analysis delays before repeating

I have an image of a ball that I am animating around a path. The animation is set to repeat forever, but why is there a delay between repeats?

Here is my code:

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); 
+6
source share
3 answers

Try the following:

 [animation setCalculationMode:kCAAnimationPaced] 
+9
source

I do not know the actual answer, but here you are doing a lot of unnecessary material, and my suggestion will be that you start by deleting it. There is no need for a CATransaction block ( begin and commit ). No need for setBeginTime: There is definitely no need to set removedOnCompletion and fillMode , as this is not a grouped animation. Just add animation to the layer and pull back. It will start immediately and repeat forever, and your code will be simpler and better.

+1
source

You must replace kCAFillModeRemoved with kCAFillModeForwards or another value. Read the documentation on why .

Additionally:

Replace:

 [arcAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]] 

C (depending on the test result):

 [arcAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]] 

or

 [arcAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]] 
0
source

All Articles