Hello.
I'm looking for some help. I have a UIViewController that display a PDF with multiple pages.
import UIKit
import PDFKit
class SafetyPDF: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let pdfView = PDFView(frame: UIScreen.main.bounds)
let url = Bundle.main.url(forResource: "FINAL_PowerPalletManual", withExtension: "pdf")
pdfView.document = PDFDocument(url: url!)
view.addSubview(pdfView)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func goBAckButton(_ sender: Any) {
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}It works. However, it covers the goBack button to navigate back to the the first viewcontroller.
Any suggestion to fix this problem?
Why are you using UIScreen.main.bounds? That's the entire screen, so the view is going to cover everything else.
You have two choices:
1. You can add autolayout constrains to the new view in your viewDidLoad, which will cause it to be resize when the view is presented.
2. Defer view creation until viewWillAppear. At that point, the view controller's view's bounds should be available, and you should be able to choose a suitable size based on those bounds.