1

I can get HTML pages, YouTube videos, etc. to load into this WKWebView and display correctly, but PDFs tint the entire view, are cropped at the bottom, and cover the background of the nav bar when scrolled up. I want the PDF to only display in the safe area below the nav bar.

Here's my code:

// 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)

I've tried adding

webView.autoresizesSubviews = true
webView.autoresizingMask = [.flexibleHeight, .flexibleWidth]

from this Stack Overflow answer and it doesn't help.

Here are screenshots of the issues I'm seeing:

Dark tinted background everywhere

PDF cut off at bottom and covering nav bar background

Please help! Thank you!

user3753722
  • 153
  • 2
  • 11

2 Answers2

0

I've also had issues with WKWebViews (PDFs not displaying in certain situations) and as such I just use UIWebViews instead right now. UIWebViews are discouraged so this isn't an ideal solution, but it may prove to be a quick fix for now.

Simba
  • 177
  • 13
0

I'm seeing issues where WKWebView won't show PDF markup when pulled from a URL. I believe this is a similar issue. Still occurs on iOS11.3.1. I switched back to UIWebView. I was using UIWebView until recently anyway.

Sparky
  • 31
  • 5