gpt4 book ai didi

ios - WKwebview 未显示事件指示器

转载 作者:行者123 更新时间:2023-11-30 11:05:16 24 4
gpt4 key购买 nike

我正在尝试在 WKWebView 中加载网页。实际上效果很好。但是,我在显示进度指示器(UIActivityIndi​​caatorView())时遇到问题。我不知道做错了什么。我已经尝试了很多解决方案。请帮忙

    var activityIndicator:UIActivityIndicatorView = UIActivityIndicatorView()
var webView:WKWebView!

override func viewDidLoad() {
super.viewDidLoad()
// Setting up webview
let webConfiguraton = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguraton)
webView.uiDelegate = self
view.addSubview(webView)
let myURL = URL(string:"link")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
webView.addObserver(self, forKeyPath: #keyPath(WKWebView.isLoading), options: .new, context: nil)
// setting up activity indicator
activityIndicator.center = self.view.center
activityIndicator.hidesWhenStopped = true
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray
view.addSubview(activityIndicator)
activityIndicator.startAnimating()
// Do any additional setup after loading the view.
}

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "loading"{
if webView.isLoading{

} else {

}
}
}

最佳答案

WKWebView 似乎没有显示,因为您将其 frame 大小设置为 .zero。您可以尝试这样设置:

webView = WKWebView(frame: self.view.frame, configuration: webConfiguraton)

关于ios - WKwebview 未显示事件指示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52803176/

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