Reputation: 239
As detailed in a previous post (Here), I'm creating an animation that starts at an initial angle and moves to an ending angle. I've decided to use CADisplayLink
for this animation because the animation needs to run as fast as possible during user input, so a CALayer
with a CAKeyframeAnimation
seemed like it would be too slow to achieve this.
After implementing the CADisplayLink
, which calls setNeedsDisplay
, I do have the animation working, but it looks really bad because it chunks up the difference between endAngle and initialAngle into heavily visible blocks of angles instead of creating a continuous flow from one angle to the next. Here's the current code I have:
CGFloat newAngleToAnimate = animationProgress + ((endAngle-initialAngle)/kDrawDuration)*elapsedTime;
// Use newAngleToAnimate to draw in drawInContext
animationProgress = newAngleToAnimate; // Update the progress for the next frame.
Also, kDrawDuration
is defined as 3.0f
, so I want the animation from initialAngle
to endAngle
to take 3.0 seconds. I break up the full circle (2*M_PI
radians) into equal segments by calculating 2*M_PI / kNumAnglesInAnimation
, and preferably I want to animate one of those angles every frame, but somehow I still have to take kDrawDuration
and elapsedTime
into account, which I'm just not seeing how to achieve.
Thanks for any help with fixing this!
Upvotes: 0
Views: 622
Reputation: 2403
CGFloat newAngleToAnimate = animationProgress + ((endAngle-initialAngle)/kDrawDuration)*elapsedTime;
don't track "animationProgress". Your elapsedTime is all you need in order to get your animation correct. So just remove it and use:
CGFloat newAngleToAnimate = ((endAngle-initialAngle)/kDrawDuration)*elapsedTime;
Upvotes: 1