WKWebView的PDF是否被导航栏切断?

时间:2018-12-01 20:55:33

标签: ios uinavigationcontroller uinavigationbar wkwebview

因此,我有一个视图控制器,该控制器将WKWebView设置为其视图,并从网站加载PDF。但是navigationBar会切掉PDF的顶部,但不会在加载网站时将其切掉。有人知道如何解决吗?

class WebView: UIViewController, WKNavigationDelegate {
    var webView: WKWebView!
    var urlString: String?
    var pdf: NSData?

    override func loadView() {
        webView = WKWebView()
        webView.navigationDelegate = self
        view = webView
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        navigationItem.largeTitleDisplayMode = .never

        let url = URL(string: urlString ?? "https://www.cpp.edu")!
        webView.load(URLRequest(url: url))
        pdf = NSData(contentsOf: url)
        navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(shareTapped))

    }

    @objc func shareTapped() {
        let view = UIActivityViewController(activityItems: [pdf!], applicationActivities: nil)
        present(view, animated: true)
    }
}

enter image description here

enter image description here

0 个答案:

没有答案