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