【问题标题】:How to know when user swipes to next page in PDFView of PDFKit?如何知道用户何时在 PDFKit 的 PDFView 中滑动到下一页?
【发布时间】:2018-05-22 13:53:15
【问题描述】:

在我的 iOS 应用程序中,我使用 PDFView 和 pdfView.usePageViewController(true, withViewOptions: nil)。

当用户滑动到另一个页面时,我想隐藏PDFThumbnailView。

我已经查看了PDFViewDelegate,但是没有合适的函数可以使用。

【问题讨论】:

    标签: ios swift pdfkit pdfview


    【解决方案1】:

    您可以尝试像这样为 PDFViewPageChanged 通知添加观察者

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

    然后处理换页事件:

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

    希望对你有帮助

    【讨论】:

    • 我收到了一个InvalidArgumentException 。应该是这样的 addObserver(self, ... object: pdfView) 。否则它会尝试在PDFView 对象上调用handlePageChange。编辑您的答案,我会将其标记为正确:)
    • 知道如何获取新页面吗? :)
    【解决方案2】:

    使用PDFViewPageChanged 通知

    斯威夫特

    // Add page change observer
    NotificationCenter.default.addObserver(self,
                selector: #selector(pageDidChange(notification:)),
                  name: Notification.Name.PDFViewPageChanged,
                  object: nil)
    
     @objc private func pageDidChange(notification: Notification) {
          // pdfView is of type PDFView
          let currentPageNumber = pdfView.document?.index(for: pdfView.currentPage!)
     }
    

    目标 C

    // Add page change observer
    [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(pageDidChange:) name:PDFViewPageChangedNotification object:nil];
    
    - (void) pageDidChange:(NSNotification *)notification {
        
    // _pdfView is of type PDFView
        NSUInteger currentPageNumber = [_pdfView.document indexForPage:_pdfView.currentPage];
        
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-26
      • 2019-11-10
      • 1970-01-01
      • 2019-10-04
      • 2021-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多