Animating Drawing Values
I've done similar animations in CoreGraphics, so you may want to take a look at that as an alternative if you can't get CAShapeAnimation
to work for you. I've got a progress view here that has this sort of animation except in a linear fashion.
- (void)setProgress:(CGFloat)progress {
self.progressToAnimateTo = progress;
if (self.animationTimer) {
[self.animationTimer invalidate];
}
self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:0.008 target:self selector:@selector(incrementAnimatingProgress) userInfo:nil repeats:YES];
}
- (void)incrementAnimatingProgress {
if (_progress >= self.progressToAnimateTo-0.01 && _progress <= self.progressToAnimateTo+0.01) {
_progress = self.progressToAnimateTo;
[self.animationTimer invalidate];
[self setNeedsDisplay];
} else {
_progress = (_progress < self.progressToAnimateTo) ? _progress + 0.01 : _progress - 0.01;
[self setNeedsDisplay];
}
}
This technique of using another property such as progressToAnimateTo
and incrementing the progress
value before redrawing could also be harnessed to then redraw the progress of a circle.
Resources
I might also add that there are other implementations of what you're doing here. MBProgressHUD and EVCircularProgressView have this sort of effect.