IOS瀏覽檔案doc.txt.pdf等等

來源:互聯網
上載者:User

一、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];

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.