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!

1
  • Did you ever found a solution to this? Commented Nov 21, 2018 at 11:23

3 Answers 3

2

Try pdfView.displayMode = .singlePageContinuous

Sign up to request clarification or add additional context in comments.

1 Comment

It’s not the same experience as singlePage... I know it works, but I am looking for a singlePage navigation
2

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

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

PDFView-PageViewController

Comments

0

In this case, DisplayMode = .SinglePage, but this also causes problems with multiple pages, so the displayMode should be taken by the number of pages and changed accordingly.

if pdfView.document!.pageCount == 1 {
     pdfView.displayMode = .singlePage
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.