Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. CGPDFDocumentRef PDFfile;
  2. CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("iPhoneAppProgrammingGuide.pdf"), NULL, NULL);
  3. PDFfile = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
  4. CFRelease(pdfURL);
  5.  
  6.  
  7. -(void)drawRect:(CGRect)rect
  8. {
  9. {
  10. totalpagenumpers=CGPDFDocumentGetNumberOfPages(PDFfile);
  11. navBar.title = [NSString stringWithFormat:@"(%d/%d)",currentpage,totalpagenumpers];
  12. CGPDFPageRef page = CGPDFDocumentGetPage(PDFfile,currentpage);
  13. context = UIGraphicsGetCurrentContext();
  14. CGContextSaveGState(context);
  15. CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
  16. CGContextFillRect(context,self.bounds);
  17. CGContextTranslateCTM(context, -1.0, [self bounds].size.height);
  18. CGContextScaleCTM(context, 1.0, -1.0);
  19. CGContextConcatCTM(context, CGPDFPageGetDrawingTransform(page, kCGPDFArtBox, [self bounds], 0, true));
  20. CGContextDrawPDFPage(context, page);
  21. CGContextRestoreGState(context);
  22. CGAffineTransform transform = aspectFit(CGPDFPageGetBoxRect(page, kCGPDFMediaBox),
  23. CGContextGetClipBoundingBox(context));
  24. CGContextConcatCTM(context, transform);
  25. UIGraphicsBeginImageContext(CGSizeMake(self.bounds.size.width, self.bounds.size.height));
  26.  
  27. }
  28.  
  29.  
  30.  
  31. }
  32.  
  33.  
  34.  
  35.  
  36. -(void)Next
  37. {
  38. size_t pageCount = CGPDFDocumentGetNumberOfPages(PDFfile);
  39. if (currentpage == pageCount)
  40. {
  41. NSLog(@"aaaaa");
  42. }
  43. else
  44. {
  45.  
  46.  
  47. [UIView beginAnimations:nil context:NULL];
  48. [UIView setAnimationDuration:1.0];
  49. [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self cache:YES];
  50. [UIView commitAnimations];
  51.  
  52. currentpage++;
  53.  
  54. [self setNeedsDisplay];
  55. }
  56.  
  57. }
  58.  
  59. -(void)Previous
  60. {
  61.  
  62. if (currentpage == 1||currentpage<1)
  63. {
  64. {
  65. NSLog(@"11111");
  66.  
  67. }
  68.  
  69. }
  70. else
  71. {
  72.  
  73. [UIView beginAnimations:nil context:NULL];
  74. [UIView setAnimationDuration:1.0];
  75. [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self cache:YES];
  76. // self.modalTransitionStyle = UIModalTransitionStylePartialCurl;
  77.  
  78. [UIView commitAnimations];
  79. currentpage--;
  80. [self setNeedsDisplay];
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement