自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iPhone開發(fā)應用中PDF案例實現(xiàn)

移動開發(fā) iOS
iPhone開發(fā)應用中PDF案例實現(xiàn)是本文要介紹的內(nèi)容,主要是來學習iPhone開發(fā)中PDF的解析內(nèi)容,文章內(nèi)容不多,主要是基于代碼來實現(xiàn)。來看詳細內(nèi)容。

iPhone開發(fā)應用中PDF案例實現(xiàn)是本文要介紹的內(nèi)容,主要是來學習iPhone開發(fā)PDF的解析內(nèi)容,文章內(nèi)容不多,主要是基于代碼來實現(xiàn)。來看詳細內(nèi)容。

  1. #import <UIKit/UIKit.h> 
  2. @class PDFTestViewController;  
  3. @interface PDFView : UIView {  
  4.  //這個類封裝了PDF畫圖得所有信息  
  5.  CGPDFDocumentRef pdf;  
  6.  //PDFDocument 中得一頁  
  7.  CGPDFPageRef page;  
  8.  //總共頁數(shù)  
  9.  int totalPages;  
  10.  //當前得頁面  
  11.  int currentPage;  
  12.  PDFTestViewController *pdftest;  
  13. }  
  14. @property(nonatomic,retain)IBOutlet PDFTestViewController *pdftest;  
  15. //當前視圖初始化類,在該方法中會創(chuàng)建一個CGPDFDocuemntRef對象,傳遞一個PDF文件得名字,和所需要頁面得大小,  
  16. - (id)initWithFrame:(CGRect)frame andFileName:(NSString *)fileName;  
  17. //創(chuàng)建一個PDF對象,此方法在初始化方法中被調(diào)用  
  18. - (CGPDFDocumentRef)createPDFFromExistFile:(NSString *)aFilePath;  
  19.  
  20. -(void)reloadView;  
  21. /*  
  22.  頁面之間得跳轉(zhuǎn)  
  23.  */  
  24. -(void)goUpPage;     
  25. -(void)goDownPage;  
  26. @end  
  27. //  
  28. //  PDFView.m  
  29. //  PDFViewTest  
  30. //  
  31. //  Created by Evan Lynn on 10-6-20.  
  32. //  Copyright 2010 Tera Age. All rights reserved.  
  33. //  
  34.  
  35. #import "PDFView.h"  
  36.  
  37. //#import "PDFTestViewController.h"  
  38. @implementation PDFView  
  39. @synthesize pdftest;  
  40. - (id)initWithFrame:(CGRect)frame andFileName:(NSString *)fileName{  
  41.  if (self = [super initWithFrame:frame]) {  
  42.  NSString *dataPathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];  
  43.  pdf = [self createPDFFromExistFile:dataPathFromApp];  
  44.  self.backgroundColor = [UIColor clearColor];  
  45.  }  
  46.  return self;  
  47. }  
  48. - (CGPDFDocumentRef)createPDFFromExistFile:(NSString *)aFilePath{  
  49.  CFStringRef path;  
  50.  CFURLRef url;  
  51.  CGPDFDocumentRef document;  
  52. path = CFStringCreateWithCString(NULL, [aFilePath UTF8String], kCFStringEncodingUTF8);  
  53. url = CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, NO);  
  54.  CFRelease(path);  
  55. document = CGPDFDocumentCreateWithURL(url);  
  56.  CFRelease(url);  
  57. totalPages = CGPDFDocumentGetNumberOfPages(document);  
  58. currentPage=1;  
  59. if (totalPages == 0) {  
  60. return NULL;  
  61. }  
  62. return document;  
  63. }  
  64. - (void)drawRect:(CGRect)rect {  
  65. //得到繪圖上下文環(huán)境  
  66.     CGContextRef context = UIGraphicsGetCurrentContext();  
  67. //得到一個PDF頁面  
  68.     page = CGPDFDocumentGetPage(pdf, currentPage);  
  69. /*進行坐標轉(zhuǎn)換向右移動100個單位,并且向下移動當前視圖得高度,  
  70. 這是因為Quartz畫圖得坐標系統(tǒng)是以左下角為開始點,但iphone視圖是以左上角為開始點  
  71.  */  
  72.     CGContextTranslateCTM(context, 100.0,self.bounds.size.height);  
  73. //轉(zhuǎn)變坐標系  
  74.     CGContextScaleCTM(context, 1.0, -1);  
  75.     CGContextDrawPDFPage(context, page);  
  76. }  
  77. - (void)dealloc {  
  78.     [super dealloc];  
  79. }  
  80. -(void)reloadView{  
  81. [self setNeedsDisplay];  
  82. }  
  83. -(void)goUpPage{  
  84. if(currentPage < 2)  
  85. return;  
  86. --currentPage;  
  87. [self reloadView];  
  88. }  
  89. -(void)goDownPage{  
  90. if(currentPage >=totalPages)  
  91. return;  
  92. ++currentPage;  
  93. [self reloadView];  
  94. }  
  95. @end 

小結(jié):iPhone開發(fā)應用中PDF案例實現(xiàn)的內(nèi)容介紹完了,希望通過本文的學習能對你有所幫助!

責任編輯:zhaolei 來源: 互聯(lián)網(wǎng)
相關推薦

2011-08-18 16:24:44

iPhone開發(fā)圖片

2011-08-16 15:48:37

iPhone開發(fā)抓圖程序

2011-08-19 11:10:31

iPhone應用

2011-08-19 10:13:05

iPhone開發(fā)

2011-08-18 15:24:40

iPhone國際化

2011-08-19 10:05:30

iPhone開發(fā)

2011-08-17 16:12:20

iPhone應用程序

2011-08-18 16:42:07

iPhone應用APNS推送

2011-08-15 11:23:41

iPhone開發(fā)循環(huán)滾動UIScrollVie

2011-08-15 18:02:32

iPhone開發(fā)表視圖

2011-08-10 17:37:00

iPhoneASIHTTPRequ

2011-08-16 15:36:47

iPhone應用測試

2011-08-17 16:23:31

iPhone開發(fā)UIViewContr

2011-08-22 14:12:48

iPhone開發(fā)NSTableView

2011-08-15 11:37:20

iPhone開發(fā)Mask

2011-08-09 17:12:30

iPhoneCFRunLoop

2011-08-12 14:33:06

iPhone緩存文件

2011-08-19 10:01:09

iPhone應用SqliteUITableView

2012-04-26 13:26:58

iPhone應用技巧

2011-07-25 14:44:41

iPhone iPhone開發(fā) 截屏
點贊
收藏

51CTO技術棧公眾號