我有一个在 WKWebView 上使用来显示本地文件路径的应用程序。它转到另一个视图控制器,然后使用新的 html 文件路径展开到原始控制器。我已经让它加载新的文件路径,但只有在索引文件闪烁一秒钟之后。无论如何要清除此视图?
覆盖 func viewWillAppear(_ animated: Bool) {
如果 unwindingFromPost == true {
let htmlPath = Bundle.main.path(forResource: "card/card", ofType: "html", inDirectory: "pickles_ui")
let url = URL(fileURLWithPath: htmlPath!)
let request = URLRequest(url: url)
webView.scrollView.bounces = false
webView.load(request)
} else {
let htmlPath = Bundle.main.path(forResource: "index", ofType: "html", inDirectory: "pickles_ui")
let url = URL(fileURLWithPath: htmlPath!)
let request = URLRequest(url: url)
webView.scrollView.bounces = false
webView.load(request)
}
}
}