【发布时间】:2020-09-24 12:49:00
【问题描述】:
我在网页视图上显示 html 字符串。但是在 webview 上显示需要 2-3 秒。当我从一个屏幕切换到另一个屏幕时,必须同时显示 Web 视图内容。 我该怎么做?
查看控制器1
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func actionOpenWebView(_ sender: Any) {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "ViewController2") as! ViewController2
self.navigationController?.pushViewController(vc, animated: true)
}
}
查看控制器2
import UIKit
import WebKit
class ViewController2: UIViewController {
@IBOutlet weak var webView: WKWebView!
let str = "Coconut couscous with berries, poppy seeds and natural yogurt Coconut couscous with berries, poppy seeds and natural yogurt Coconut couscous with berries, poppy seeds and natural yogurt"
override func viewDidLoad() {
super.viewDidLoad()
webView.loadHTMLString(str, baseURL: nil)
webView.uiDelegate = self
webView.navigationDelegate = self
}
@IBAction func actionBack(_ sender: UIButton) {
self.navigationController?.popViewController(animated: true)
}
}
extension ViewController2: WKUIDelegate, WKNavigationDelegate {
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
print("Show Web View Content Successfully")
}
}
【问题讨论】:
标签: ios swift wkwebview webviewdidfinishload