zoukankan      html  css  js  c++  java
  • ios在项目中打开word文档、ppt等总结

    最近在项目开发中遇到下载附件文档预览需求,在这里总结一下我的实现方法

    这里我总结了三种实现方法(1)用webView预览(2)通过UIDocumentInteractionController实现跳转(3)应用Quick Look系统框架,下面依次介绍各个方法实现

    首先来看用webView这个比较常用,不做过多解释,代码如下:

    _webView = [[UIWebView alloc]initWithFrame:self.view.bounds];
        _webView.delegate = self;
        NSURLRequest *request = [NSURLRequest requestWithURL:_url1];
        [_webView loadRequest:request];
        [_webView setScalesPageToFit:YES];
        [self.view addSubview:_webView];
    

     第二种应用UIDocumentInteractionController实现方法如下:

    //先初始化对象,以及设置弹出方式
    _documentInt = [UIDocumentInteractionController interactionControllerWithURL:_url2];
        [_documentInt setDelegate:self];
        [_documentInt presentPreviewAnimated:YES];
        [_documentInt presentOptionsMenuFromRect:CGRectMake(0, 0, 375, 667) inView:self.view  animated:YES];
    //然后实现相应代理方法
    - (UIViewController*)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController*)controller
    {
         return self;
    }
    - (UIView*)documentInteractionControllerViewForPreview:(UIDocumentInteractionController*)controller
    {
         return self.view;
    }
    - (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController*)controller
    {
        
         return self.view.frame;
    }
    //点击预览窗口的“Done”(完成)按钮时调用
    - (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController*)_controller
    {
        [_documentInt dismissPreviewAnimated:YES];
    }
    

     第三种Quick Look,用这个方法需要导入QuickLook.FrameWork框架,代码如下:

    //初始化对象
    QLPreviewController *myQlPreViewController = [[QLPreviewController alloc]init];
        myQlPreViewController.delegate =self;
        myQlPreViewController.dataSource =self;
        [myQlPreViewController setCurrentPreviewItemIndex:0];
        [self presentViewController:myQlPreViewController animated:YES completion:nil];
    //实现代理方法
    - (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
    {
        return 1;
    }
    - (id)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
    {
        //    NSString *fileName = [self.listDic objectForKey:@"fileName"];
        //    NSString* path = [NSHomeDirectory()stringByAppendingPathComponent:[NSStringstringWithFormat:@"Documents/%@",fileName]];
        
        return _url3;
        
    }
    
  • 相关阅读:
    html+css 笔记
    JS随手笔记
    JQ几个淡入淡效果
    AngularJS编译阶段应分为两个阶段
    JavaScript 原型链的理解
    js继承的6种方式
    什么是跨域?跨域解决方法
    computed (计算属性) 和 methods (方法) 的区别
    谈谈vue生命周期
    基本类型有哪几种?null 是对象吗?基本数据类型和复杂数据类型存储有什么区别?
  • 原文地址:https://www.cnblogs.com/zk1947/p/6101741.html
Copyright © 2011-2022 走看看