gpt4 book ai didi

ios - 如何正确更新导航 Controller 下方的 UIProgressView?

转载 作者:行者123 更新时间:2023-11-29 12:07:32 25 4
gpt4 key购买 nike

我的目标是导航栏下方的进度条,正如您在这张截图中所见,它工作得非常好:

enter image description here

这是创建它的代码:

class NavigationController: UINavigationController {

let progressView = UIProgressView(progressViewStyle: .Bar)

override func viewDidLoad() {
super.viewDidLoad()

progressView.progress = 0.9
view.addSubview(progressView)

let bottomConstraint = NSLayoutConstraint(item: navigationBar, attribute: .Bottom, relatedBy: .Equal, toItem: progressView, attribute: .Bottom, multiplier: 1, constant: 1)
let leftConstraint = NSLayoutConstraint(item: navigationBar, attribute: .Leading, relatedBy: .Equal, toItem: progressView, attribute: .Leading, multiplier: 1, constant: 0)
let rightConstraint = NSLayoutConstraint(item: navigationBar, attribute: .Trailing, relatedBy: .Equal, toItem: progressView, attribute: .Trailing, multiplier: 1, constant: 0)

progressView.translatesAutoresizingMaskIntoConstraints = false
view.addConstraints([bottomConstraint, leftConstraint, rightConstraint])
progressView.setProgress(0.8, animated: true)
}
}

但是当我尝试通过按下上传按钮来更新进度值时,

for value in [0.0, 0.25, 0.5, 0.75, 1.0] {
NSThread.sleepForTimeInterval(0.5)
let navC = navigationController as! NavigationController // shorthand
navC.progressView.setProgress(Float(value), animated: true)
let isMainThread = NSThread.isMainThread() // yes, it is main thread
let currentValue = navC.progressView.progress // yes, the value is updated
}

没有任何反应,但对于最后一个值 1.0 突然进度已满。我究竟做错了什么?

最佳答案

var queue = dispatch_queue_create("a", nil)
dispatch_async(queue, {
for value in [0.0, 0.25, 0.5, 0.75, 1.0] {
NSThread.sleepForTimeInterval(0.5)

dispatch_async(dispatch_get_main_queue(), {
let navC = navigationController as! NavigationController // shorthand
navC.progressView.setProgress(Float(value), animated: true)
})
}
})

关于ios - 如何正确更新导航 Controller 下方的 UIProgressView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34527614/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com