• 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;
        
    }
    
  • 相关阅读:
    filp_open/filp_close/vfs_read/vfs_write
    memcpy一种实现方法
    memset函数的实现&printf函数几种输出格式的输出结果
    break退出循环分析
    定义指针变量作为返回值函数执行时报 段错误(核心已转储)
    node实现防盗链
    js实现输入密码之延迟星号和点击按钮显示或隐藏
    rem适配
    使用字蛛教程以及遇到的bug
    es6学习笔记-proxy对象
  • 原文地址:https://www.cnblogs.com/zk1947/p/6101741.html
Copyright © 2020-2023  润新知