【问题标题】:PDFKit: How to move current page in PDFView to a specific offsetPDFKit:如何将 PDFView 中的当前页面移动到特定偏移量
【发布时间】:2019-10-04 18:33:43
【问题描述】:

假设 PDF 中只有一页。 我要实现的目标:保存当前正在查看的 PDFPage 的缩放和偏移量,并在用户返回该页面时以完全相同的偏移量和缩放级别显示页面。 我所取得的成就: 计算偏移量和缩放并在页面重新加载时,成功显示保存的页面缩放级别。我无法设置偏移量。 尝试使用以下方法,但没有效果。

1)

[_pdfView goToRect:rect onPage:[_pdfView.document pageAtIndex: page.unsignedLongValue ]];

2)

PDFDestination *destination =  [_pdfView.currentDestination initWithPage:[_pdfView.document pageAtIndex: page.unsignedLongValue ] atPoint:viewPoint];
    [_pdfView goToDestination:destination];

【问题讨论】:

    标签: ios objective-c swift pdfview ios-pdfkit


    【解决方案1】:

    我能够使用 goToRect 完成此任务。我认为 goToDestination 存在问题。它总是导航到与我进入它不同的位置。

    这是我在退出 pdf 时保存位置的方法(请注意,我从 Swift 翻译了这段代码,尚未在 Objective C 中进行测试):

        CGFloat savedScaleFactor = _pdfView.scaleFactor;
        //I use this to find the first page shown in my view. If you only have one page,
        //you can just use currentPage
        PDFPage *page = [_pdfView pageForPoint:CGPointZero nearest:YES];
        CGRect savedRect = [_pdfView convertRect:_pdfView.bounds toPage:page];
        NSInteger savedIndex = [_pdfView.document indexForPage:page];
    

    然后恢复位置:

        _pdfView.scaleFactor = savedScaleFactor;
        PDFPage *page = [_pdfView.document pageAtIndex:savedIndex];
        [_pdfView goToRect:savedRect onPage:page];
    

    【讨论】:

      猜你喜欢
      • 2013-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-03
      • 1970-01-01
      • 2020-11-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多