Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (id)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:(CGRect)frame];
- if (self) {
- self.backgroundColor = [UIColor clearColor];
- NSString *pathToPdfDoc = [[NSBundle mainBundle] pathForResource:@"myPDF" ofType:@"pdf"];
- NSURL *pdfUrl = [NSURL fileURLWithPath:pathToPdfDoc];
- document = CGPDFDocumentCreateWithURL((CFURLRef)pdfUrl);
- currentPage = 1;
- }
- return self;
- }
- -(void)drawRect:(CGRect)inRect{
- if(document) {
- CGPDFPageRef page = CGPDFDocumentGetPage(document, currentPage);
- CGContextRef ctx = UIGraphicsGetCurrentContext();
- CGContextSaveGState(ctx);
- CGContextTranslateCTM(ctx, 0.0, [self bounds].size.height);
- CGContextScaleCTM(ctx, 1.0, -1.0);
- CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, [self bounds], 0, true));
- CGContextDrawPDFPage(ctx, page);
- CGContextRestoreGState(ctx);
- }
- }
- -(void)increasePageNumber {
- size_t pageCount = CGPDFDocumentGetNumberOfPages(document);
- if (currentPage == pageCount) {
- // do nothing
- }
- else {
- currentPage++;
- [self setNeedsDisplay];
- }
- }
- -(void)decreasePageNumber {
- if (currentPage == 1) {
- // do nothing
- }
- else {
- currentPage--;
- [self setNeedsDisplay];
- }
- }
- -(void)viewDidLoad {
- CGRect frame;
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
- frame = CGRectMake(0, 0, 960, 1024);
- }
- else{
- frame = CGRectMake(0, 0, 320, 460);
- }
- tiledLayer = [CATiledLayer layer];
- tiledLayer.delegate = self;
- tiledLayer.tileSize = CGSizeMake(1024, 1024);
- tiledLayer.levelsOfDetail = 200;
- tiledLayer.levelsOfDetailBias = 200;
- tiledLayer.frame = frame;
- myPDFView = [[viewPDF alloc] initWithFrame:frame];
- //[self.view addSubview:myPDFView];
- [myPDFView.layer addSublayer:tiledLayer];
- CGRect viewFrame = self.view.frame;
- viewFrame.origin = CGPointZero;
- scrollView = [[UIScrollView alloc] initWithFrame:viewFrame];
- scrollView.delegate = self;
- scrollView.contentSize = frame.size;
- scrollView.maximumZoomScale = 5;
- [scrollView addSubview:myPDFView];
- [self.view addSubview:scrollView];
- }
- - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
- {
- return myPDFView;
- }
Add Comment
Please, Sign In to add comment