• 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;
        
    }
    
  • 相关阅读:
    Go接口特性
    go递归函数
    K8S部署Redis Cluster集群(三主三从模式) 部署笔记
    Jenkins密码忘记重置方法
    inode满了处理
    Linux 系统日常巡检脚本
    垃圾代码评析——关于《C程序设计伴侣》6.2(三)
    CRITICAL THINGKING笔记——ad hominem
    垃圾代码评析——关于《C程序设计伴侣》6.2(二)
    垃圾代码评析——关于《C程序设计伴侣》6.2(一)
  • 原文地址:https://www.cnblogs.com/zk1947/p/6101741.html
Copyright © 2020-2023  润新知