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;
        
    }
    
  • 相关阅读:
    uboot如何检测XC2440是从Nand或Nor启动
    uboot中的快捷菜单的制作说明
    Android存储数据方式
    SharedPreferences详解
    (转载)Android理解:显式和隐式Intent
    使用 Fresco加载图片
    script "text/template"
    网页动画插件---Super Scrollorama , TweenMax 和skrollr
    Android控件之HorizontalScrollView 去掉滚动条
    android编程取消标题栏方法(appcompat_v7、Theme.NoTitleBar)
  • 原文地址:https://www.cnblogs.com/zk1947/p/6101741.html
Copyright © 2011-2022 走看看