因此,我有一个视图控制器,该控制器将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)
}
}