我正在使用下面的 github 项目
https://github.com/jackhumphries/UIPageViewController-PDF
问题是 pdf 正在加载并且页面卷曲效果正在工作,但我无法放大和缩小我加载的 pdf 文档我尝试调试以及为什么它不工作但我找不到解决方案,我检查了PDFScrollView 委托方法它们都已实现,但是当我尝试放大/缩小时这些方法没有调用。
以下是这些方法:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.tiledPDFView;
}
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view
{
// Remove back tiled view.
[self.oldTiledPDFView removeFromSuperview];
// Set the current TiledPDFView to be the old view.
self.oldTiledPDFView = self.tiledPDFView;
[self addSubview:self.oldTiledPDFView];
}
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
// Set the new scale factor for the TiledPDFView.
_PDFScale *= scale;
// Calculate the new frame for the new TiledPDFView.
CGRect pageRect = CGPDFPageGetBoxRect(_PDFPage, kCGPDFMediaBox);
pageRect.size = CGSizeMake(pageRect.size.width*_PDFScale, pageRect.size.height*_PDFScale);
// Create a new TiledPDFView based on new frame and scaling.
TiledPDFView *tiledPDFView = [[TiledPDFView alloc] initWithFrame:pageRect scale:_PDFScale];
[tiledPDFView setPage:_PDFPage];
// Add the new TiledPDFView to the PDFScrollView.
[self addSubview:tiledPDFView];
self.tiledPDFView = tiledPDFView;
}
我有这个代码:
-(id)initWithPDFAtPath:(NSString *)path {
NSURL *pdfUrl = [NSURL fileURLWithPath:path];
PDFDocument = CGPDFDocumentCreateWithURL((__bridge CFURLRef)pdfUrl);
totalPages = (int)CGPDFDocumentGetNumberOfPages(PDFDocument);
self = [super initWithNibName:nil bundle:nil];
return self;
}
我想在下面的代码中实现这个代码
/*
Open the PDF document, extract the first page, and pass the page to the PDF scroll view.
*/
NSURL *pdfURL = [[NSBundle mainBundle] URLForResource:@"TestPage" withExtension:@"pdf"];
CGPDFDocumentRef PDFDocument = CGPDFDocumentCreateWithURL((__bridge CFURLRef)pdfURL);
CGPDFPageRef PDFPage = CGPDFDocumentGetPage(PDFDocument, 1);
[(PDFScrollView *)self.view setPDFPage:PDFPage];
CGPDFDocumentRelease(PDFDocument);