title: Resize PDF View when device orientation changes
body: <p>I have a ViewController in my app that allows the user to open a PDF. The app supports landscape and portrait orientation the of device. I am having a problem when the user changes the devices orientation after opening the PDF. The PDF has two pages:
  Page 1 - All pink and
  Page 2 - All purple</p>
  
  <p>I am encountering a framing problem once the PDF is opened and the user changes the devices orientation. If the PDF is opened in a portrait orientation, the pdf only fills up half of the screen once the ordination of the device is changed to landscape:
  <a href="https://i.stack.imgur.com/LlFyK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LlFyK.png" alt="Portrait Orientation after being opened in a portrait orientation"></a>
  <a href="https://i.stack.imgur.com/0NbOg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0NbOg.png" alt="Landscape Orientation after being opened in portrait orientation"></a></p>
  
  <p>Likewise, if the PDF is opened in a Landscape orientation, the pdf will only show on half of the screen once the orientation of the device is portrait:
  <a href="https://i.stack.imgur.com/aPcVC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aPcVC.png" alt="Lanscape Orientation after being opened in a landscape Orientation"></a>
  <a href="https://i.stack.imgur.com/Hx5wG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Hx5wG.png" alt="Portrait Orientation after being opened in a landscape Orientation"></a></p>
  
  <p>Here is my code:</p>
  
  <pre><code>import UIKit
  import PDFKit
  
  class PDFfun: UIViewController {
  
      var pdfView = PDFView()
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      pdfView = PDFView(frame: self.view.frame)
  
      if let documentURL = Bundle.main.url(forResource: "Blank", withExtension: "pdf"),
          let document = PDFDocument(url: documentURL),
          let _ = document.page(at: 0) {
  
          pdfView.document = document
          pdfView.autoScales = true
          pdfView.backgroundColor = UIColor.lightGray
          pdfView.autoScales = true
  
       }
      override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
          super.viewWillTransition(to: size, with: coordinator)
          if UIDevice.current.orientation.isLandscape {
              print("landscape")
              pdfView = PDFView(frame: view.frame)
              pdfView.autoScales = true
          } else {
              print("portait")
              pdfView = PDFView(frame: view.frame)
              pdfView.autoScales = true
          }
      }
  }
  </code></pre>
  
  <p>I tired adding <code>override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)</code> fix my problem but I notice no change.</p>