3

假设 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];
4

1 回答 1

3

我能够使用 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];
于 2019-08-30T22:45:49.280 回答