gpt4 book ai didi

ios - 使用 CGPDF 滚动到特定页面

转载 作者:行者123 更新时间:2023-11-29 01:10:26 24 4
gpt4 key购买 nike

我对过去两天没有找到任何与 CGPDF 相关的适当文件感到震惊。我尝试了所有可能的方法,但我失败了。这就是我想要做的。我有一个要显示的 PDF,我正在 UIWebView 中显示它。我使用 pdf 所在的路径 (NSURL) 创建了一个 CORE GRAPHICS PDF 文档引用。我在它上面创建了一个 UIView 并处理了一个触摸事件。当 PDF 加载并且用户单击 View 时,我希望页面滚动到特定页面。我知道这可以通过计算页面高度和宽度来完成。我想知道 CGPDF 中是否有一种方法可以传递页码并滚动到相关页面。下面是我的代码

- (void)viewDidLoad
{
[super viewDidLoad];

// set the pdfPafeHeight to -1 so it gets calculated.
self.pdfPageHeight = -1;

// set the delegate of the UIWebView's underlying UIScrollView to self.
self.webView.scrollView.delegate = self;

// create an NSURLRequest to load the PDF file included with the project
_filePath = [[NSBundle mainBundle] pathForResource:@"Sample" ofType:@"pdf"];
_url = [NSURL fileURLWithPath:_filePath isDirectory:NO];
_urlRequest = [NSURLRequest requestWithURL:_url];

// create a Core Graphics PDF Document ref using the same NSURL
_pdf = CGPDFDocumentCreateWithURL((CFURLRef) _url);

// use CGPDFDocumentGetNumberOfPages to get the number of pages in the document
self.pdfPageCount = (int)CGPDFDocumentGetNumberOfPages(_pdf);

// load the PDF file into the UIWebVie

UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleSingleTap:)];
[self.view addGestureRecognizer:singleFingerTap];

[self.webView loadRequest:_urlRequest];
}

这是我想要在 UIVIEW 上处理单击的方式。我只是想知道 CGPDF 中是否有任何方法可以在我将页码传递给它时滚动到特定页面

- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {


}

最佳答案

没有 API 可以实现您想要实现的目标,即使您能够使用私有(private) API,如果此应用程序仅用于企业安装并且不需要转到 App Store - 这将很棘手并且任何解决方法都可能会随着 iOS 版本的重大更新而失效。如果你想走这条路,你可以内省(introspection) View Controller 层次结构,你会发现Apple内部有一个名为 CorePDF 的框架。它有一个您可能能够访问的内部私有(private) API - 但要小心并知道这不是 App Store 应用程序的解决方案。

另一种方法是从头开始,使用 CGContextDrawPDFPage 绘制 PDF 页面,构建您自己的缓存、 ScrollView 和 View Controller +手势处理。我们用商业广告做到了 PSPDFKit SDK我自 2010 年起就开始从事这项工作 - 这比你想象的要多。我们最终还继续使用自定义渲染器来提高与各种可用 PDF 文件的兼容性,并提供比 Apple 渲染器更好的性能,但并非每个用例都需要这样做。

关于ios - 使用 CGPDF 滚动到特定页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35827458/

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