我正在使用html
显示WKWebView
文件。当您从主WKWebView
打开另一个预加载的WKWebView
时,有时在显示白屏之后,会发生此问题。当您看到屏幕时,它会闪烁。
Main.js
$(document).ready(function(){
var data = {
apiType : "preload",
parameter : encodeURI(`view/other?value="testvalue"`)
}
webkit.messageHandlers.TestApp.postMessage(data);
...
$('#openBtn').on('click', function(){
var data = {
apiType : "openOther"
}
webkit.messageHandlers.TestApp.postMessage(data);
MainWKWebViewController.swift
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
case "preload":
let parameter = message["parameter"] as! String
preload(parameter)
break
case "openOther":
openOtherScreen()
break
...
func preload(_ prameter: String){
let storyboard = UIStoryboard(name: "Main", bundle: nil)
otherWebView = storyboard.instantiateViewController(withIdentifier: "OtherWebViewController") as? OtherWebViewController
otherWebView.delegate = self
otherWebView.paramFromMain = prameter
otherWebView.loadViewIfNeeded()
otherWebView.otherWebView.navigationDelegate = self
preloadCheck = true
}
func openOtherScreen(){
if preloadCheck {
DispatchQueue.main.async {
self.navigationController?.pushViewController(self.otherWebView, animated: true)
self.preloadCheck = false
}
} else {
}
}
有人知道为什么有时会显示白色屏幕,闪烁并显示吗?还是有人解决了与我相同的问题?
func preload(_ prameter: String){
let storyboard = UIStoryboard(name: "Main", bundle: nil)
otherWebView = storyboard.instantiateViewController(withIdentifier: "OtherWebViewController") as? OtherWebViewController
otherWebView.delegate = self
otherWebView.paramFromMain = prameter
otherWebView.view.layoutIfNeeded()
DispatchQueue.main.async {
self.otherWebView.loadViewIfNeeded()
self.otherWebView.otherWebView.navigationDelegate = self
self.preloadCheck = true
}
}
我该如何解决这个问题?