Search code examples
iosswiftpdfkitpdfview

How to know when user swipes to next page in PDFView of PDFKit?


In my iOS-App I'm using a PDFView with pdfView.usePageViewController(true, withViewOptions: nil).

I want to hide the PDFThumbnailView when the user swipes to another page.

I already looked inside PDFViewDelegate but there's no suitable function to use.


Solution

  • you can try adding observer for PDFViewPageChanged notification like this

    // Add page changed listener
    NotificationCenter.default.addObserver(
          self,
          selector: #selector(handlePageChange(notification:)),
          name: Notification.Name.PDFViewPageChanged,
          object: pdfView)
    

    And then handle the page change event :

    @objc private func handlePageChange(notification: Notification)
    {
        // Do your stuff here like hiding PDFThumbnailView...
    }
    

    Hope it helps