Skip to content

Commit a7f5352

Browse files
committed
Added initial delay feature: optional property to delay the animation. Verified in testing that this works, but there is a slight flicker at the end of the animation. I believe this is due to the storing of the progress on circularProgressLayer at the end of the animation. That progress cannot be stored before the animation starts, otherwise during the initial delay the new value is already visible.
Signed-off-by: Erik van der Neut <[email protected]>
1 parent 9bbc231 commit a7f5352

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

DACircularProgress/DACircularProgressView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@
2121
@property(nonatomic) NSInteger indeterminate UI_APPEARANCE_SELECTOR; // Can not use BOOL with UI_APPEARANCE_SELECTOR :-(
2222

2323
- (void)setProgress:(CGFloat)progress animated:(BOOL)animated;
24+
- (void)setProgress:(CGFloat)progress animated:(BOOL)animated initialDelay:(CFTimeInterval)initialDelay;
2425

2526
@end

DACircularProgress/DACircularProgressView.m

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@ - (void)setProgress:(CGFloat)progress
174174
}
175175

176176
- (void)setProgress:(CGFloat)progress animated:(BOOL)animated
177+
{
178+
[self setProgress:progress animated:animated initialDelay:0.0];
179+
}
180+
181+
- (void)setProgress:(CGFloat)progress
182+
animated:(BOOL)animated
183+
initialDelay:(CFTimeInterval)initialDelay
177184
{
178185
[self.layer removeAnimationForKey:@"indeterminateAnimation"];
179186
[self.circularProgressLayer removeAnimationForKey:@"progress"];
@@ -185,11 +192,19 @@ - (void)setProgress:(CGFloat)progress animated:(BOOL)animated
185192
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
186193
animation.fromValue = [NSNumber numberWithFloat:self.progress];
187194
animation.toValue = [NSNumber numberWithFloat:pinnedProgress];
195+
animation.beginTime = CACurrentMediaTime() + initialDelay;
196+
animation.delegate = self;
188197
[self.circularProgressLayer addAnimation:animation forKey:@"progress"];
189198
} else {
190199
[self.circularProgressLayer setNeedsDisplay];
200+
self.circularProgressLayer.progress = pinnedProgress;
191201
}
192-
self.circularProgressLayer.progress = pinnedProgress;
202+
}
203+
204+
- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)flag
205+
{
206+
NSNumber *pinnedProgressNumber = [animation valueForKey:@"toValue"];
207+
self.circularProgressLayer.progress = [pinnedProgressNumber floatValue];
193208
}
194209

195210
#pragma mark - UIAppearance methods

0 commit comments

Comments
 (0)