在iOS 10的WKWebView中打开PDF文件时启用“捏到缩放”手势

时间:2019-02-21 23:17:01

标签: ios ios10 wkwebview

我正在寻找一种在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")
       }
}

0 个答案:

没有答案