[英]Enable Pinch to Zoom gesture when open PDF file in WKWebView on iOS 10
I'm looking for a way to enable the "pinch to zoom" magnification gesture when open the local PDF file in WKWebview on iOS 10. As I know the pinch to zoom is enabled on the iOS 12我正在寻找一种在 iOS 10 上的 WKWebview 中打开本地 PDF 文件时启用“捏合缩放”放大手势的方法。据我所知,在 iOS 12 上启用了捏合缩放
class ViewController: UIViewController {
var wkWebView: WKWebView?
@IBOutlet var webView: UIView!
fileprivate var delegate = AuthenticatedWebViewNavigationDelegate()
override func viewDidLoad() {
super.viewDidLoad()
if wkWebView == nil {
createWebView()
}
let filePath = Bundle.main.path(forResource: "local", ofType:
"pdf")
let baseUrl = URL(fileURLWithPath: filePath!)
wkWebView?.loadFileURL(baseUrl, allowingReadAccessTo: baseUrl)
}
}
class AuthenticatedWebViewNavigationDelegate: NSObject, WKNavigationDelegate {
weak var viewController: ViewController?
public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
decisionHandler(.allow)
}
public func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) {
decisionHandler(.allow)
}
public func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
print("error")
}
public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
print("finish")
}
public func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
print("error")
}
}
I found the scrollview.pinchGestureRecognizer is disabled on the wkwebview of iOS 10我发现在 iOS 10 的 wkwebview 上禁用了 scrollview.pinchGestureRecognizer
So the solution is to enable the pinchGestureRecognizer, I put the function in the following function:所以解决办法是启用pinchGestureRecognizer,我把这个函数放在下面的函数中:
public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
if #available(iOS 11.0, *) {
} else {
if webView.url?.scheme == "file" {
webView.scrollView.pinchGestureRecognizer?.isEnabled = true
}
}
print("finish")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.