閱讀PDF的後果
辦法一:應用webview
-(void)loadDocument:(NSString *)documentName inView:(UIWebView *)webView
{
NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:nil];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
利:1.完成簡略
2.照樣完成簡略
弊:1.僅能閱讀,拿不就任何回調,safari不會鳥任何人。
2.固定豎版拖動,想完成翻頁動後果就扒瞎
上面的辦法可以處理webview 顯示pdf的弊,絕對的,要支付一些汗水作為價值了。
辦法二:應用CGContextDrawPDFPage
CGPDFDocumentRef GetPDFDocumentRef(NSString *filename)
{
CFStringRef path;
CFURLRef url;
CGPDFDocumentRef document;
size_t count;
path = CFStringCreateWithCString (NULL, [filename UTF8String], kCFStringEncodingUTF8);
url = CFURLCreateWithFileSystemPath (NULL, path, kCFURLPOSIXPathStyle, 0);
CFRelease (path);
document = CGPDFDocumentCreateWithURL (url);
CFRelease(url);
count = CGPDFDocumentGetNumberOfPages (document);
if (count == 0) {
printf("[%s] needs at least one page!\n", [filename UTF8String]);
return NULL;
} else {
printf("[%ld] pages loaded in this PDF!\n", count);
}
return document;
}
void DisplayPDFPage (CGContextRef myContext, size_t pageNumber, NSString *filename)
{
CGPDFDocumentRef document;
CGPDFPageRef page;
document = GetPDFDocumentRef (filename);
page = CGPDFDocumentGetPage (document, pageNumber);
CGContextDrawPDFPage (myContext, page);
CGPDFDocumentRelease (document);
}
如許顯示出來的pdf單頁是倒立的,Quartz坐標系和UIView坐標系紛歧樣而至,調劑坐標系,使pdf正立:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 80, self.frame.size.height-60);
CGContextScaleCTM(context, 1, -1);
合營IOS5壯大的UIPageViewController完成翻頁閱讀
- (PDFViewController *)viewControllerAtIndex:(NSUInteger)index
{
//Return the PDFViewController for the given index.
if (([self.pagePDF count] == 0 )|| (index > [self.pagePDF count]) ) {
return nil;
}
//Create a new view controller and pass suitable data.
PDFViewController *dataViewController = [[PDFViewController alloc]initWithNibName:@"PDFViewController" bundle:nil];
//dataViewController.pdfview = [self.pagePDF objectAtIndex:index];
dataViewController.pdfview = [[PDFView alloc]initWithFrame:self.view.frame atPage:index];
[dataViewController.view addSubview:dataViewController.pdfview];
NSLog(@"index = %d",index);
return dataViewController;
}
- (NSUInteger) indexOfViewController:(PDFViewController *)viewController
{
return [self.pagePDF indexOfObject:viewController.pdfview];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger index = [self indexOfViewController:(PDFViewController *)viewController];
if ((index == 0 ) || (index == NSNotFound)){
return nil;
}
index--;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger index = [self indexOfViewController:(PDFViewController *)viewController];
if (index == NSNotFound)
{
return nil;
}
index++;
if (index == [self.pagePDF count]){
return nil;
}
return [self viewControllerAtIndex:index];
}
塗鴉後果
重要觸及:
1. 多context,分層畫畫
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
2. 觸摸事宜touches族那些event
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
……
3. 初始化單頁view傳頁碼
- (id)initWithFrame:(CGRect)frame onPage:(NSInteger)page
4.畫軌跡辦法
CG_EXTERN void CGPathMoveToPoint(CGMutablePathRef path,
const CGAffineTransform *m, CGFloat x, CGFloat y)
CG_EXTERN void CGPathAddLineToPoint(CGMutablePathRef path,
const CGAffineTransform *m, CGFloat x, CGFloat y)
【iOS下PDF文件的閱讀和塗鴉後果的簡略完成】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!