一、UIDocumentInteractionController全螢幕顯示
#import <Foundation/Foundation.h>@interface LLFileVC : UIViewController<UIDocumentInteractionControllerDelegate>{ BOOL _isShowing; NSURL *_docURL;}@property (nonatomic, retain) UIDocumentInteractionController *docInteractionController;-(id)initWithURL:(NSURL*)aURL;@end
#import "LLFileVC.h"@implementation LLFileVC@synthesize docInteractionController;-(id)initWithURL:(NSURL *)aURL{ if (self=[super init]) { _isShowing = NO; _docURL = [aURL retain]; } return self;}-(void)dealloc{ [docInteractionController release]; [_docURL release]; [super dealloc];}-(void)showFile{ if (_docURL) { self.docInteractionController = [UIDocumentInteractionController interactionControllerWithURL:_docURL]; self.docInteractionController.delegate = self; if (![self.docInteractionController presentPreviewAnimated:YES]){ } }}-(void)viewDidAppear:(BOOL)animated{ if (!_isShowing) { [self showFile]; }else{ [self dismissModalViewControllerAnimated:NO]; } [super viewDidAppear:animated];}#pragma mark -#pragma mark UIDocumentInteractionControllerDelegate- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller{ return self;}- (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller{ return self.view;}- (BOOL)documentInteractionController:(UIDocumentInteractionController *)controller canPerformAction:(SEL)action{ BOOL canPerform = NO; if (action == @selector(copy:)) canPerform = YES; return canPerform;}- (BOOL)documentInteractionController:(UIDocumentInteractionController *)controller performAction:(SEL)action{ BOOL handled = NO; if (action == @selector(copy:)){ handled = YES; } return handled;}- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController*)controller{return self.view.frame;}- (void)documentInteractionControllerWillBeginPreview:(UIDocumentInteractionController *)controller{ _isShowing = YES;}- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft|| interfaceOrientation == UIInterfaceOrientationLandscapeRight) {return YES;}else {return NO;}}@end
//調用全屏瀏覽
NSString *rootPath = [self getDocumentsPath]; NSString *filePath = [NSString stringWithFormat:@"%@/doc/%@",rootPath,_downLoadName]; LLFileVC *aLLFileVC = [[[LLFileVC alloc] initWithURL:[NSURL fileURLWithPath:filePath]] autorelease]; AppDelegate *app = (AppDelegate*)[UIApplication sharedApplication].delegate; [app.window.rootViewController presentModalViewController:aLLFileVC animated:NO];
二、UIWebView顯示局部View
if (!_webView) { _webView = [[UIWebView alloc] initWithFrame:_contentView.bounds]; _webView.scalesPageToFit = YES; [_contentView addSubview:_webView]; } NSString *rootPath = [self getDocumentsPath]; NSString *filePath = [NSString stringWithFormat:@"%@/weekdoc/%@",rootPath,[NSString stringWithFormat:@"%@",[aDic objectForKey:@"wjm"]]]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]; [_webView loadRequest:request];