Guest User

Untitled

a guest
Jul 17th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. - (id)initWithFrame:(CGRect)frame {
  2.  
  3. self = [super initWithFrame:(CGRect)frame];
  4. if (self) {
  5. self.backgroundColor = [UIColor clearColor];
  6. NSString *pathToPdfDoc = [[NSBundle mainBundle] pathForResource:@"myPDF" ofType:@"pdf"];
  7. NSURL *pdfUrl = [NSURL fileURLWithPath:pathToPdfDoc];
  8. document = CGPDFDocumentCreateWithURL((CFURLRef)pdfUrl);
  9. currentPage = 1;
  10. }
  11. return self;
  12. }
  13.  
  14. -(void)drawRect:(CGRect)inRect{
  15. if(document) {
  16. CGPDFPageRef page = CGPDFDocumentGetPage(document, currentPage);
  17. CGContextRef ctx = UIGraphicsGetCurrentContext();
  18. CGContextSaveGState(ctx);
  19. CGContextTranslateCTM(ctx, 0.0, [self bounds].size.height);
  20. CGContextScaleCTM(ctx, 1.0, -1.0);
  21. CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, [self bounds], 0, true));
  22. CGContextDrawPDFPage(ctx, page);
  23. CGContextRestoreGState(ctx);
  24. }
  25. }
  26.  
  27. -(void)increasePageNumber {
  28. size_t pageCount = CGPDFDocumentGetNumberOfPages(document);
  29. if (currentPage == pageCount) {
  30. // do nothing
  31. }
  32. else {
  33. currentPage++;
  34. [self setNeedsDisplay];
  35. }
  36. }
  37.  
  38. -(void)decreasePageNumber {
  39. if (currentPage == 1) {
  40. // do nothing
  41. }
  42. else {
  43. currentPage--;
  44. [self setNeedsDisplay];
  45. }
  46. }
  47.  
  48. -(void)viewDidLoad {
  49. CGRect frame;
  50.  
  51. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  52. frame = CGRectMake(0, 0, 960, 1024);
  53.  
  54. }
  55. else{
  56. frame = CGRectMake(0, 0, 320, 460);
  57.  
  58. }
  59.  
  60. tiledLayer = [CATiledLayer layer];
  61. tiledLayer.delegate = self;
  62. tiledLayer.tileSize = CGSizeMake(1024, 1024);
  63. tiledLayer.levelsOfDetail = 200;
  64. tiledLayer.levelsOfDetailBias = 200;
  65. tiledLayer.frame = frame;
  66.  
  67. myPDFView = [[viewPDF alloc] initWithFrame:frame];
  68. //[self.view addSubview:myPDFView];
  69.  
  70. [myPDFView.layer addSublayer:tiledLayer];
  71.  
  72. CGRect viewFrame = self.view.frame;
  73. viewFrame.origin = CGPointZero;
  74. scrollView = [[UIScrollView alloc] initWithFrame:viewFrame];
  75. scrollView.delegate = self;
  76. scrollView.contentSize = frame.size;
  77. scrollView.maximumZoomScale = 5;
  78. [scrollView addSubview:myPDFView];
  79.  
  80. [self.view addSubview:scrollView];
  81.  
  82. }
  83.  
  84. - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
  85. {
  86. return myPDFView;
  87. }
Add Comment
Please, Sign In to add comment