我可以将 HTML 页面、YouTube 视频等加载到此 WKWebView 中并正确显示,但 PDF 会为整个视图着色,在底部被裁剪,并在向上滚动时覆盖导航栏的背景。我希望 PDF 仅显示在导航栏下方的安全区域中。
这是我的代码:
// add web view
let webConfiguration = WKWebViewConfiguration()
let customFrame = CGRect.init(origin: CGPoint.zero, size: CGSize.init(width: 0, height: self.view.frame.size.height))
let webView = WKWebView (frame: customFrame, configuration: webConfiguration)
webView.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(webView)
webView.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
webView.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
webView.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
webView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
webView.heightAnchor.constraint(equalTo: self.view.heightAnchor).isActive = true
webView.uiDelegate = self
// embed pdf in web view
let pdfUrl = URL(string: self.pdfUrlString)
let pdfRequest = URLRequest(url: pdfUrl!)
webView.load(pdfRequest)
我试过添加
webView.autoresizesSubviews = true
webView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
从这个 Stack Overflow 答案,它并没有帮助。
以下是我看到的问题的屏幕截图:
请帮忙!谢谢!