How to display pdf on iOS

后端 未结 12 1153
半阙折子戏
半阙折子戏 2020-12-12 18:30

I want to know if there is any way for a offline build for xcode iOS such that we can display pdf file from local file.

The method I\'m using now is vi

12条回答
  •  渐次进展
    2020-12-12 18:49

    In my case, I have a tableView that segues to a PDFView based on either a selected row or detail indicator (there are two different ViewControllers for each in different parts of my app). I have an @IBOutlet for the PDFView and use this code to open the desired PDF, which is saved in the app:

    @IBOutlet weak var myPDFView: PDFView!
    
    var mySelection = String()
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        if let path = Bundle.main.path(forResource: mySelection, ofType: "pdf") {
            let url = URL(fileURLWithPath: path)
    
            if let myDocument = PDFDocument(url: url) {
                myPDFView.document = myDocument
                myPDFView.autoScales = true
                myPDFView.displayMode = .singlePageContinuous
                myPDFView.displayDirection = .vertical
                myPDFView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
            }
        }
    }
    

    This all works great. The correct PDFs load easily and fill the screen like I want. However, the PDF is always scrolled up just a little, causing the top portion to be hidden under the navigation bar. Notice in the screen shot below that the top of the document is not visible but the bottom is, just above the tab bar at the bottom. I think this has to do with PDF coordinates starting at the bottom of the page but cannot figure out how to get it to load the very top of the document, so the background at the top is visible.

    Simulator Screen Shot Link

    Perhaps this has to do with autoScales?

提交回复
热议问题