3

I am trying to make a vertical scrolling PDFView using the following code:

pdfView = PDFView(frame: view.frame)
pdfView.backgroundColor = UIColor.white

var documentName: String = "test"

if let documentURL = Bundle.main.url(forResource: documentName, withExtension: "pdf") {
    if let document = PDFDocument(url: documentURL) {
        pdfView.displayDirection = .vertical
        pdfView.usePageViewController(true, withViewOptions: nil)
        pdfView.document = document
    }
}

self.view.addSubview(pdfView)

It displays fine, but the displayDirection is horizontal, not vertical. I'm trying to find a way to set the withViewOptions, but I can't find relevant info on this.

I checked on SO, and many people suggest to add displayDirection but that doesn't see to change anything.

On the other hand, when I try to run the following code:

pdfView = PDFView(frame: view.frame)
pdfView.backgroundColor = UIColor.white

var documentName: String = "test"

if let documentURL = Bundle.main.url(forResource: documentName, withExtension: "pdf") {
    if let document = PDFDocument(url: documentURL) {
        pdfView.autoScales = true
        pdfView.displayDirection = .vertical
        pdfView.displayMode = .singlePage
        pdfView.document = document
    }
}

self.view.addSubview(pdfView)

It just displays the first page and it doesn't scroll. I need to add swipe gestures recognizers and the scroll is not smooth. Beside, it seems overkill for a single page scrolling functionality...

Am I missing something? Any help would be greatly appreciated!

Jeremie
  • 2,241
  • 2
  • 17
  • 25

2 Answers2

2

Try pdfView.displayMode = .singlePageContinuous

  • 1
    It’s not the same experience as singlePage... I know it works, but I am looking for a singlePage navigation – Jeremie Mar 30 '18 at 06:44
2

The only thing you need to do is use the following method from PDFView:

pdfView.usePageViewController(true, withViewOptions: [:])

PDFView-PageViewController

Diogo Antunes
  • 2,241
  • 1
  • 22
  • 37