gpt4 book ai didi

objective-c - 将 PDFPage 添加到 PDFDocument 时 PDFView 不更新

转载 作者:行者123 更新时间:2023-12-03 16:57:24 28 4
gpt4 key购买 nike

我正在制作一个应用程序来扫描多页 pdf 文件。我有一个链接的 PDFViewPDFThumbnailView 。第一次扫描完成时,我创建一个新的 PDFDocument 并将其设置为 PDFView。然后,每当另一次扫描完成时,我都会将 PDFPage 添加到 [pdfView document]

现在的问题是,每当添加页面时,PDFViewPDFThumbnailView 都不会更新以显示带有额外页面的新文档。直到我放大或缩小,然后它们都会更新以显示带有新页面的文档。

我现在的临时解决方案(放大然后自动缩放)当然不是最好的解决方案。例如,当您已经放大文档并扫描新页面时, View 将自动缩放。我之前尝试过 [pdfView setNeedsDisplay:YES] 但似乎不起作用。

这是扫描作为 NSData 到达的方法:

- (void)scannerDevice:(ICScannerDevice *)scanner didScanToURL:(NSURL *)url data:(NSData *)data {
//Hide the progress bar
[progressIndicator stopAnimation:nil];

//Create a pdf page from the data
NSImage *image = [[NSImage alloc] initWithData:data];
PDFPage *page = [[PDFPage alloc] initWithImage:image];

//If the pdf view has a document
if ([pdfView document]) {
//Set the page number and add it to the document
[page setValue:[NSString stringWithFormat:@"%d", [[pdfView document] pageCount] + 1] forKey:@"label"];
[[pdfView document] insertPage:page atIndex:[[pdfView document] pageCount]];
} else {
//Create a new document and add the page
[page setValue:@"1" forKey:@"label"];
PDFDocument *document = [[PDFDocument alloc] init];
[document insertPage:page atIndex:0];
[pdfView setDocument:document];
}

//Force a redraw for the pdf view so the pages are shown properly
[pdfView zoomIn:self];
[pdfView setAutoScales:YES];
}

有谁知道我可以添加 PDFPage 并更新 PDFView 而不扰乱 PDFView 的缩放状态的方法吗? ?

最佳答案

您需要手动调用:

- (void)layoutDocumentView

我想不手动调用它的原因是为了允许将多个更改合并到一个更新中。

这已记录在案:

The PDFView actually contains several subviews, such as the document view (where the PDF is actually drawn) and a “matte view” (which may appear as a gray area around the PDF content, depending on the scaling). Changes to the PDF content may require changes to these inner views, so you must call this method explicitly if you use PDF Kit utility classes to add or remove a page, rotate a page, or perform other operations affecting visible layout.

This method is called automatically from PDFView methods that affect the visible layout (such as setDocument:, setDisplayBox: or zoomIn:).

关于objective-c - 将 PDFPage 添加到 PDFDocument 时 PDFView 不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21517685/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com