Reputation: 71
I want to reset (set progress to 0) my UIProgressView after the following code:
// uploadProgress: UIProgressView!
uploadProgress.progress = 0
uploadProgress.setProgress(1.0, animated: true)
I can't set uploadProgress.progress to 0 right after this block because then no animation will appear.
I don't want to edit the animation duration either.
I just want the progress to go back to 0 AFTER the animation is fully complete.
I would greatly appreciate your help. Thank you in advance!
Upvotes: 0
Views: 2964
Reputation: 4143
A bit late but I came across the same problem and this is how I solve it. Since the animation on the UIProgressView
is done on the layer, we can use CATransaction
's completion block to capture when the animation has ended.
CATransaction.begin()
CATransaction.setCompletionBlock({
// do whatever you want when the animation is completed
self.progressBar.hidden = true
})
self.progressBar.setProgress(1.0, animated: true)
CATransaction.commit()
Upvotes: 4
Reputation: 1341
You could use the animation UIView.animate function with the completion handler.
UIView.animateWithDuration(1, animations: { () -> Void in
self.progressBar.setProgress(1, animated: true)
}, completion: { (Bool) -> Void in
progressBar.progress = 0
})
Upvotes: 1