1

I have a view with different pdf documents and I'd like to be able to detect when each document reaches the last page.

My approach is to observe PDFViewPageChanged notifications

documentId = ...
obs = NotificationCenter.default.addObserver(forName: .PDFViewPageChanged, object: nil, queue: nil) { (notification) in ...

      guard let notificationPdfView = notification.object as? PDFView,
            let currentPage = notificationPdfView.currentPage?.pageRef?.pageNumber,
            let totalPageNumber = notificationPdfView.document?.pageCount,
            let docStringCount = notificationPdfView.document?.string else { return }

      print("FB: notification: \(documentId) currentPage: \(currentPage)/\(totalPageNumber)" )
 }

and then to check if the current page is equal to to document total pages number.

The only problem is that I get notifications that tell me that the current page has changed even before I touch the pdf file and in some cases the condition of the document being scrolled until the last page is falsely satisfied.

FB: notification: Document 1 currentPage: 1/2
FB: notification: Document 1 currentPage: 1/2
FB: notification: Document 1 currentPage: 2/2 // <---- 
FB: notification: Document 1 currentPage: 1/2

Any clues on why this can occur?

onthemoon
  • 3,302
  • 3
  • 17
  • 24

0 Answers0