Hi at all, I try to do a pdf viewer with multipage and zoom, the zoom work while the multipage has some problem, if I change the page the page not change but if I zoom the view change and I view the correct page, if I put zoomscale=1 I see the wrong page.
this is my code:
where is the mistake for you?
this is my code:
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
currentPage=1;
NSString *pathToPdfDoc = [[NSBundle mainBundle] pathForResource:@"myPDF" ofType:@"pdf"];
NSURL *pdfUrl = [NSURL fileURLWithPath:pathToPdfDoc];
myDocumentRef = CGPDFDocumentCreateWithURL((CFURLRef)pdfUrl);
CGRect pageRect = CGRectMake(0, 0, 320, 480);
tiledLayer = [CATiledLayer layer];
tiledLayer.delegate = self;
tiledLayer.tileSize = CGSizeMake(1024.0, 1024.0);
tiledLayer.levelsOfDetail = 1000;
tiledLayer.levelsOfDetailBias = 1000;
tiledLayer.frame = pageRect;
pdfView = [[UIView alloc] initWithFrame:pageRect];
[pdfView.layer addSublayer:tiledLayer];
CGRect viewFrame = self.view.frame;
viewFrame.origin = CGPointZero;
scrollView = [[UIScrollView alloc] initWithFrame:viewFrame];
scrollView.delegate = self;
scrollView.contentSize = pageRect.size;
scrollView.maximumZoomScale = 1000;
[scrollView addSubview:pdfView];
[self.view addSubview:scrollView];
[self gesture];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return pdfView;
}
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
{
CGPDFPageRef page = CGPDFDocumentGetPage(myDocumentRef, currentPage);
CGContextSaveGState(ctx);
CGContextTranslateCTM(ctx, 0.0, layer.bounds.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, layer.bounds, 0, true));
CGContextDrawPDFPage(ctx, page);
CGContextRestoreGState(ctx);
}
-(void)increasePageNumber {
size_t pageCount = CGPDFDocumentGetNumberOfPages(myDocumentRef);
if (currentPage == pageCount) {
// do nothing
}
else {
currentPage++;
[pdfView setNeedsDisplay];
}
}
where is the mistake for you?