Alex Bent
Alex Bent

Reputation: 137

UIProgressView setProgress animation is messed up

For some reason, UIProgressView.setProgress(1, animate: true) causes a messed up animation to occur. The picture below shows the problem. First off, it animates from the center outward and it starts slightly above its actual location. enter image description here

So here is the full view controller code that contains the UIProgressView

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var progressBar: UIProgressView!

    override func viewDidLoad() {
        super.viewDidLoad()
        progressBar.setProgress(1, animated: true)
    }
}

Upvotes: 0

Views: 1473

Answers (2)

Bruno Ramos
Bruno Ramos

Reputation: 159

The problem here, it's you're setting up your progress view before your view loading done. You can force "building" progress view before setting up you progress using layoutIfNeeded() method.

override func viewDidLoad() {
    super.viewDidLoad()
    progressBar.layoutIfNeeded()
    progressBar.setProgress(1, animated: true)
}

Upvotes: 1

Alex Bent
Alex Bent

Reputation: 137

The problem was the setProgress was called in viewDidLoad which messed it up. It needed to be called in another method that is called after the view is fully loaded such as viewDidAppear as suggested by Paulw11 and Randy

Upvotes: 1

Related Questions