我有一个带有按钮的网页会触发一些动作,我想在网页视图可以返回时在UI上显示“后退”按钮。桌面浏览器和webview上的滑动手势可以正确处理此操作(即浏览器显示后退按钮并向后滑动可正常工作)。但由于某种原因,此操作不会触发任何WKNavigationDelegate回调。 Webview和以下回调看起来可以在VC中正确设置:
webView.navigationDelegate = self
decidePolicyForNavigationAction
didStartProvisionalNavigation
didFinishNavigation
didReceiveServerRedirectForProvisionalNavigation
didFailNavigation
didCommitNavigation
webViewWebContentProcessDidTerminate
didReceiveAuthenticationChallenge
didFailProvisionalNavigation
即使使用观察者来查看Web视图的“加载”属性也不起作用:
webView.addObserver(self, forKeyPath: "loading", options: .New, context: nil)
override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
guard let _ = object as? WKWebView else { return }
guard let keyPath = keyPath else { return }
guard let change = change else { return }
switch keyPath {
case "loading":
// Set button
default:break
}
同一网站上其他操作的回调正常运行。 这可能是什么原因?