Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 11 PDFKit - curl transition

Tags:

ios

pdf

swift

ios11

With iOS 11, PDFKit has been made available in iOS. It has the capability of use a UIPageViewController but not to set the transition style ( documentation ).

Is there any way do change the transition style of the PageViewController of PDFView from the default to page curl?

like image 726
alessionossa Avatar asked Dec 14 '17 11:12

alessionossa


1 Answers

I've gone through the view hierarchy of a PDFView and it seems like underneath it is using UIPageViewController. However, setting the transition style to curl is not possible as the property can only be set during initialization.

One workaround I tried, though inefficient when loading PDFs with large number of pages is to create your own UIPageViewController and set its view controllers on the datasource to view controllers each containing a PDFView whose page are set to the corresponding index.

let pageCount = self.pdfDocument!.pageCount - 1
for index in 0...pageCount {
  let page: PDFPage = self.pdfDocument!.page(at: index)!
  let pdfView: PDFView = PDFView(frame: self.view.frame)
  pdfView.document = self.pdfDocument
  pdfView.displayMode = .singlePage
  pdfView.go(to: page)
  pdfView.autoScales = true
  let vc = UIViewController()
  vc.view = aView
  pages.append(vc)
}

Again this is a work around and perhaps there is a better way.

like image 138
SleepNot Avatar answered Sep 21 '22 15:09

SleepNot