iosswiftscrolluidocumentinteractionuidocumentinteractioncontroller

Programmatically scroll pdf in UIDocumentInteractionController


I'm showing a pdf file inside a UIDocumentInteractionController, like this:

let docController = UIDocumentInteractionController(url: documentsURL)
    let url = NSURL(string:"itms-books:");
    if UIApplication.shared.canOpenURL(url! as URL) {
        docController.delegate = self
        docController.presentPreview(animated: true)
    }

I need to automatically scroll to the last page when the controller is shown, is there a way to do that? I didn't find one. Thanks to anyone who will send help!


Solution

  • I am afraid there is not a straight forward solution for this, even the documentation says it's a UIViewController but Xcode shows it is inherited from NSObject. I'd recommend either rendering the PDF on a WKWebView or a UIScrollView. This will give you a room to wiggle.