diff --git a/DACircularProgress/DACircularProgressView.m b/DACircularProgress/DACircularProgressView.m index ec4e30f..013fe45 100644 --- a/DACircularProgress/DACircularProgressView.m +++ b/DACircularProgress/DACircularProgressView.m @@ -204,18 +204,24 @@ - (void)setProgress:(CGFloat)progress withDuration:(CFTimeInterval)duration { [self.layer removeAnimationForKey:@"indeterminateAnimation"]; - [self.circularProgressLayer removeAnimationForKey:@"progress"]; + // on basic animations, the value is reset to its original value once animation is finished + // to avoid this, just set the progress value before removing animation + CGFloat currentProgress = ((DACircularProgressLayer*)self.circularProgressLayer.presentationLayer).progress; + self.circularProgressLayer.progress = currentProgress; + + [self.circularProgressLayer removeAnimationForKey:@"progress"]; + CGFloat pinnedProgress = MIN(MAX(progress, 0.0f), 1.0f); if (animated) { CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"progress"]; animation.duration = duration; animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; animation.fillMode = kCAFillModeForwards; - animation.fromValue = [NSNumber numberWithFloat:self.progress]; + animation.fromValue = [NSNumber numberWithFloat:currentProgress]; animation.toValue = [NSNumber numberWithFloat:pinnedProgress]; + animation.removedOnCompletion = NO; animation.beginTime = CACurrentMediaTime() + initialDelay; - animation.delegate = self; [self.circularProgressLayer addAnimation:animation forKey:@"progress"]; } else { [self.circularProgressLayer setNeedsDisplay]; @@ -223,13 +229,6 @@ - (void)setProgress:(CGFloat)progress } } -- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)flag -{ - NSNumber *pinnedProgressNumber = [animation valueForKey:@"toValue"]; - self.circularProgressLayer.progress = [pinnedProgressNumber floatValue]; -} - - #pragma mark - UIAppearance methods - (UIColor *)trackTintColor