【问题标题】:PDF from URL not displaying correctly in WKWebView?来自 URL 的 PDF 在 WKWebView 中未正确显示?
【发布时间】:2018-03-05 15:53:03
【问题描述】:

我可以将 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]

来自this Stack Overflow answer 并没有帮助。

以下是我看到的问题的屏幕截图:

请帮忙!谢谢!

【问题讨论】:

    标签: ios swift pdf wkwebview wkwebviewconfiguration


    【解决方案1】:

    我也遇到了 WKWebViews 的问题(PDF 在某些情况下不显示),因此我现在只使用 UIWebViews。不鼓励使用 UIWebViews,因此这不是一个理想的解决方案,但它现在可能被证明是一种快速解决方案。

    【讨论】:

      【解决方案2】:

      我发现从 URL 中提取 WKWebView 时不会显示 PDF 标记的问题。我相信这是一个类似的问题。在 iOS11.3.1 上仍然发生。我切换回 UIWebView。无论如何,我直到最近才使用 UIWebView。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-12-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-13
        • 1970-01-01
        相关资源
        最近更新 更多