我正在使用下面的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);
最佳答案
将此方法添加到PDFScrollView中:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.decelerationRate = UIScrollViewDecelerationRateFast;
self.delegate = self;
self.minimumZoomScale = 1.0;
self.maximumZoomScale = 3.0;
}
return self;
}
并将最后两行添加到
scrollViewDidEndZooming
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
....
self.minimumZoomScale = 1.0/scale;
self.maximumZoomScale = 3.0*scale;
}
请注意,只有在页面处于最低缩放级别时(例如,在多个阅读器应用程序中发生这种情况),更改页面才会起作用。
关于ios - UIPageViewController-PDF缩放无法使用xcode?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19829327/