簡體   English   中英

PDFKit:如何將PDFView中的當前頁面移動到特定的偏移量

[英]PDFKit: How to move current page in PDFView to a specific offset

假設PDF中只有一個頁面。 我想要實現的目的:保存當前正在查看的PDF頁面的縮放和偏移,並在用戶返回該頁面時以完全相同的偏移和縮放級別顯示頁面。 我所取得的成果:計算偏移和縮放以及頁面重新加載,成功顯示已保存的頁面縮放級別。 我無法設置偏移量。 嘗試使用以下方法,但沒有效果。

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];

我能夠使用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];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM