probably a better approach would be to use 2 CAShapeLayers and animate a bezier path. Assume CPCircleCountdownView is a UIView Subclass
@interface CPCircleCountdownView ()
@property (nonatomic) CAShapeLayer* layer1;
@property (nonatomic) CAShapeLayer* layer2;
@property (nonatomic, assign) float startAngle;
@property (nonatomic, assign) float endAngle;
@end
@implementation CPCircleCountdownView
- (void)intiWithFrame:(CGRect) Frame
{
self = [super initWithFrame:frame];
if (self) {
_startAngle = M_PI * 1.5;
_endAngle = _startAngle + (M_PI * 2);
}
}
-(void)layoutSubviews{
self.layer1 = [CAShapeLayer layer];
self.layer1.fillColor = [UIColor clearColor].CGColor;
self.layer1.strokeColor = [UIColor redColor].CGColor;
self.layer2 = [CAShapeLayer layer];
self.layer2.fillColor = [UIColor clearColor].CGColor;
self.layer2.strokeColor = [UIColor greenColor].CGColor;
[self.layer1 setFrame:CGRectMake(50, 50, 200, 200)];
[self.layer2 setFrame:CGRectMake(50, 50, 200, 200)];
UIBezierPath *path1 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.layer1.frame.size.width / 2, self.layer1.frame.size.height / 2)
radius:130
startAngle:self.startAngle
endAngle:self.endAngle
clockwise:YES];
UIBezierPath *path2 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.layer2.frame.size.width / 2, self.layer2.frame.size.height / 2)
radius:125
startAngle:self.endAngle
endAngle:self.startAngle
clockwise:NO];
self.layer1.path = path1.CGPath;
self.layer2.path = path2.CGPath;
[self.view.layer addSublayer:self.layer1];
[self.view.layer addSublayer:self.layer2];
[self.layer1 setStrokeEnd:1.0f];
[self.layer2 setStrokeEnd:0.0f];
// i've placed this here for convenience in testing, really it should be in method called by your button Action
[self decrementSpinForValue:100];
}
- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)finished {
[self.layer1 removeAllAnimations];
[self.layer2 removeAllAnimations];
}
-(void) decrementSpinForValue:(float) percent{
CABasicAnimation *strokeEndAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
strokeEndAnimation.delegate = self;
strokeEndAnimation.duration = percent;
[strokeEndAnimation setFillMode:kCAFillModeForwards];
strokeEndAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
strokeEndAnimation.removedOnCompletion = NO;
strokeEndAnimation.fromValue = [NSNumber numberWithFloat:1.0f];
strokeEndAnimation.toValue = [NSNumber numberWithFloat:0.0f];
[self.layer1 addAnimation:strokeEndAnimation forKey:@"progressOuterStatus"];
CABasicAnimation *strokeEndAnimation2 = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
strokeEndAnimation2.duration = 1.0f;
strokeEndAnimation2.repeatCount = percent;
[strokeEndAnimation2 setFillMode:kCAFillModeForwards];
strokeEndAnimation2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
strokeEndAnimation2.removedOnCompletion = NO;
strokeEndAnimation2.fromValue = [NSNumber numberWithFloat:0.0f];
strokeEndAnimation2.toValue = [NSNumber numberWithFloat:1.0f];
[self.layer2 addAnimation:strokeEndAnimation2 forKey:@"progressInnerStatus"];
}
@end
I think that gives you an idea of how you can accomplish it.