Swift - UIProgressView fills diagonally

霸气de小男生 提交于 2019-12-24 05:38:00

问题


So I set up a UIProgressView to fill after 3 seconds as well as increasing the height of the bar a bit. However when it fills up, it fills diagonally as opposed to just filling from one side to the other. The bar starts in the top right corner and then expands to fill the progress view just before it ends.

This is the code I am using:

import UIKit

class LoadingScreen: UIViewController {


    @IBOutlet weak var progressView: UIProgressView!


    override func viewDidLoad() {
        super.viewDidLoad()

        UIView.animateWithDuration(3, animations: { () -> Void in
            self.progressView.setProgress(1.0, animated: true)
        })

        progressView.transform = CGAffineTransformScale(progressView.transform, 1, 10)

}


}

Here are some screenshots:


回答1:


Coming to this rather late but I just experienced this and fixed it by changing my progressView style to .Bar. Hope that helps!

let progressView = UIProgressView(progressViewStyle: .Bar)



回答2:


It seems that the size of the progressView is incorrect.

Try to put these code in viewDidLayoutSubviews:

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()

    UIView.animateWithDuration(3, animations: { () -> Void in
        self.progressView.setProgress(1.0, animated: true)
    })

    progressView.transform = CGAffineTransformScale(progressView.transform, 1, 10)
}


来源:https://stackoverflow.com/questions/31453454/swift-uiprogressview-fills-diagonally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!