Samy
Samy

Reputation: 1190

UIProgressView not animating progress on iOS 13

I am not seeing the animation of a UIProgressView with Xcode 11.0/Swift 5/iOS 13:

private let timerProgressView: UIProgressView = {
    let timerProgressView = UIProgressView()
    timerProgressView.progressTintColor = white
    timerProgressView.trackTintColor = .black
    timerProgressView.setProgress(1.0, animated: false)
    return timerProgressView
}()

private func triggerProgressView() {
    UIView.animate(withDuration: viewModel.timeLimit, delay: 0.0, options: .curveLinear, animations: { [weak self] in
        self?.timerProgressView.setProgress(0.0, animated: true)
    }, completion: nil)
}

This code works on iOS <12 but not on iOS 13. Am I missing something?

Upvotes: 7

Views: 3140

Answers (2)

Farshad jahanmanesh
Farshad jahanmanesh

Reputation: 885

we've faced it too and after about an hour of hair pulling we came up with a workaround, it looks like that is a bug. it ridiculous, but setting the progress to 0.0001 instead of 0.0 will do the job.

progressView.progress = 0.0001
UIView.animate(withDuration: duration,
                   delay: 0.0, options: [.curveLinear, .beginFromCurrentState, .preferredFramesPerSecond60],
                   animations: { progressView.layoutIfNeeded() },
                   completion: nil)

Upvotes: 5

atulkhatri
atulkhatri

Reputation: 11333

Did you try doing something like this? :

self?.timerProgressView.setProgress(0.0) 
UIView.animate(withDuration: viewModel.timeLimit, delay: 0.0, options: .curveLinear, animations: { [weak self] in
    self?.timerProgressView.layoutIfNeeded() 
}, completion: nil)

Upvotes: 1

Related Questions