gpt4 book ai didi

ios - 带有百分比的 UIProgressView 加载条

转载 作者:行者123 更新时间:2023-11-28 10:15:42 30 4
gpt4 key购买 nike

我想在 Swift 3 中为我的 iOS 项目制作一个加载栏。我目前正在做一个 WebView ,需要做这个加载栏来显示在 Action 之间。我知道这是假的加载栏,我在 Objective-C 中看到了代码,并试图在 Swift 中用它做出一些东西,但我担心我的逻辑是错误的,因为我是 Swift 的新手。

我遇到的问题是我不知道我是否设置了 vars theBooltimer到正确的地方,我不知道如何使用Timer() .

告诉你我在运行应用程序时看到的内容,进度条一直显示,但没有加载。

到目前为止,这是我的代码

import UIKit

class ViewController: UIViewController {
@IBOutlet weak var webView: UIWebView!
@IBOutlet weak var progressView: UIProgressView!

var theBool = false
var timer = Timer()

override func viewDidLoad() {
super.viewDidLoad()

progressView.progress = 0.0

//Reading the webview
let websiteURL = URL(string: "http://google.com")
let websiteURLRequest = URLRequest(url: websiteURL!)
webView.loadRequest(websiteURLRequest)
}

func webViewDidFinishLoad (){
if webView.isLoading == true {
theBool = true
}
}

func handleProgress () {
if (theBool){
if (progressView.progress >= 1) {
progressView.isHidden = true
timer.invalidate()
} else {
progressView.progress += 0.1
}
} else {
progressView.progress += 0.05
if (progressView.progress >= 0.95) {
progressView.progress = 0.95
}
}
}

/*
func addValsToProgress () ->String {
if (webViewLoading() == true) {
view.progressView.setProgre
}
}
*/
}

最佳答案

根据您提供的代码,您需要初始化 timer有一个时间间隔和一个 Action 。这样当定时器被调用时,它会调用 handleProgress .计时器应该 fire当加载状态开始并会定期调用handleProgress直到加载完成。此时,计时器将是 invalidated并将停止调用handleProgress .

https://developer.apple.com/reference/foundation/timer如何做到这一点。

关于ios - 带有百分比的 UIProgressView 加载条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41912300/

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