你好。我正在使用 Xcode 开发应用程序。 WKWebView 中的活动指示器在加载内容后保持旋转并且不停止或消失
Posted
技术标签:
【中文标题】你好。我正在使用 Xcode 开发应用程序。 WKWebView 中的活动指示器在加载内容后保持旋转并且不停止或消失【英文标题】:Hello. I am working on app using Xcode. The active indicator in WKWebView is keep spining and not stop or disappear after loading content 【发布时间】:2020-11-17 20:56:35 【问题描述】:import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate, WKUIDelegate
@IBOutlet weak var webView: WKWebView!
@IBOutlet weak var activeIndicator: UIActivityIndicatorView!
override func viewDidLoad()
super.viewDidLoad()
let myURL = URL(string: "https://www.google.com/")
let myRequest = URLRequest(url: myURL!)
webView.navigationDelegate = self
webView.load(myRequest)
func webViewDidStartLoad(_ webView: WKWebView)
activeIndicator.startAnimating()
func webViewDidFinishLoad(_ webView: WKWebView, didFinish navigation: WKNavigationDelegate!)
DispatchQueue.main.async
self.activeIndicator.stopAnimating()
self.activeIndicator.hidesWhenStopped = true
self.activeIndicator.isHidden = true
【问题讨论】:
【参考方案1】:import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate, WKUIDelegate
@IBOutlet weak var webView: WKWebView!
@IBOutlet weak var activeIndicator: UIActivityIndicatorView!
override func viewDidLoad()
super.viewDidLoad()
let myURL = URL(string: "https://www.google.com")
let myRequest = URLRequest(url: myURL!)
webView.navigationDelegate = self
webView.load(myRequest)
self.webView.addSubview(self.activeIndicator)
self.activeIndicator.startAnimating()
self.webView.navigationDelegate = self
self.activeIndicator.hidesWhenStopped = true
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!)
activeIndicator.stopAnimating()
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error)
activeIndicator.stopAnimating()
【讨论】:
【参考方案2】:尝试下面的代码..在视图中设置活动指示器属性确实加载..更新代码
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate, WKUIDelegate
@IBOutlet weak var webView: WKWebView!
@IBOutlet weak var activeIndicator: UIActivityIndicatorView!
override func viewDidLoad()
super.viewDidLoad()
self.activeIndicator.hidesWhenStopped = true
let myURL = URL(string: "https://www.google.com/")
let myRequest = URLRequest(url: myURL!)
webView.navigationDelegate = self
webView.load(myRequest)
func webViewDidStartLoad(_ webView: WKWebView)
activeIndicator.startAnimating()
func webViewDidFinishLoad(_ webView: WKWebView, didFinish navigation: WKNavigationDelegate!)
DispatchQueue.main.async
self.activeIndicator.stopAnimating()
【讨论】:
它还在旋转,没有隐藏以上是关于你好。我正在使用 Xcode 开发应用程序。 WKWebView 中的活动指示器在加载内容后保持旋转并且不停止或消失的主要内容,如果未能解决你的问题,请参考以下文章
RK3399驱动开发 | 04 - WK2124串口芯片驱动浅析
RK3399驱动开发 | 04 - WK2124串口芯片驱动浅析
RK3399驱动开发 | 05 - 使用lszrz压测串口传输(wk2124)