Reputation: 2411
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!
Upvotes: 3
Views: 2052
Reputation: 66
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
}
Upvotes: 0
Reputation: 2291
The only thing you need to do is use the following method from PDFView
:
pdfView.usePageViewController(true, withViewOptions: [:])
Upvotes: 2