0
iOS 용 기본 PDF 뷰어를 만들려고 노력 중입니다. PDF 만보고 특정 페이지로 이동할 수 있기를 바랍니다.CGPDFViewController 및 다중 페이지 PDF (zomming)
#import "SFPDFViewerController.h"
#import <QuartzCore/QuartzCore.h>
@implementation SFPDFViewerController
@synthesize currentPageIndex;
- (void)viewDidLoad
{
currentPageIndex = 1;
myDocumentRef = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL URLWithString:@"file:///Users/soulstorm/Desktop/Basic%20UNIX%20Tutorial.pdf"]);
myPageRef = CGPDFDocumentGetPage(myDocumentRef, currentPageIndex);
//CGRect pageRect = CGRectIntegral(CGPDFPageGetBoxRect(myPageRef, kCGPDFCropBox));
CGRect pageRect = self.view.bounds;
CATiledLayer *tiledLayer = [CATiledLayer layer];
tiledLayer.delegate = self;
tiledLayer.tileSize = CGSizeMake(200.0, 200.0);
tiledLayer.levelsOfDetail = 1000;
tiledLayer.levelsOfDetailBias = 1000;
tiledLayer.frame = pageRect;
myContentView = [[UIView alloc] initWithFrame:pageRect];
[myContentView.layer addSublayer:tiledLayer];
CGRect viewFrame = self.view.frame;
viewFrame.origin = CGPointZero;
viewFrame.size.height-= 44;
scrollView = [[UIScrollView alloc] initWithFrame:viewFrame];
scrollView.delegate = self;
scrollView.contentSize = pageRect.size;
scrollView.maximumZoomScale = 3.0;
[scrollView addSubview:myContentView];
[self.view addSubview:scrollView];
[self.view setBackgroundColor:[UIColor whiteColor]];
[scrollView setBackgroundColor:[UIColor whiteColor]];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return myContentView;
}
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
{
NSLog(@"draw layer...");
CGContextSetRGBFillColor(ctx, 1.0, 1.0, 1.0, 1.0);
CGContextFillRect(ctx, CGContextGetClipBoundingBox(ctx));
CGContextTranslateCTM(ctx, 0.0, layer.bounds.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(myPageRef, kCGPDFCropBox, layer.bounds, 0, true));
CGContextDrawPDFPage(ctx, myPageRef);
}
#pragma mark - Functions
- (IBAction)goToNextPage:(id)sender
{
[self displayNextPage];
}
- (IBAction)goToPreviewsPage:(id)sender
{
[self displayPreviewsPage];
}
- (void)displayNextPage
{
currentPageIndex++;
[self reloadCurrentPage];
}
- (void)displayPreviewsPage
{
currentPageIndex--;
[self reloadCurrentPage];
}
- (void)reloadCurrentPage
{
NSLog(@"reloading current page... %i", currentPageIndex);
myPageRef = CGPDFDocumentGetPage(myDocumentRef, currentPageIndex);
//[self.view setNeedsDisplay];
//[self.view.layer setNeedsDisplay];
//[myContentView.layer setNeedsDisplay];
}
#pragma mark -
- (void)dealloc
{
[myContentView release];
myContentView = nil;
CGPDFDocumentRelease(myDocumentRef);
myDocumentRef = NULL;
myPageRef = NULL;
[super dealloc];
}
@end
위의 코드는 corectly PDF 파일의 첫 페이지에 표시하지만 다음 페이지로 이동하려고 할 때, 그것은 처음에 남아 : 여기
내가 지금까지 한 일이다 때로는 확대/축소 할 때 두 번째 페이지의 일부를 볼 수 있습니다.누구나 올바른 방향으로 나를 가리킬 수 있습니까?