【发布时间】:2016-03-06 13:31:49
【问题描述】:
过去两天我没有找到任何与 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 {
}
【问题讨论】:
标签: ios objective-c xcode cgpdf