iOS提供了使用其他app预览文件的支持,这就是Document Interaction Controller。此外,iOS也支持文件关联,允许其他程序调用你的app打开某种文件。而且,从4.2开始,Quick Look Framework提供了对多种文档的内置打印。你可以参考DocumentInteraction Controller类参考以及Quick Look Framework指南,以及DocInteraction示例程序。
本文讨论了Document InteractionController的使用。
-、创建实例
 DocumentInteraction Controller使用静态方法interactionControllerWithURL创建实例,这个方法使用一个NSURL作为参数。
 代码:
 NSURL *url=[NSURL fileURLWithPath:path];
 controller = [UIDocumentInteractionController  interactionControllerWithURL:url];
 二、显示预览窗口
 Document Interaction Controller对象使用presentPreviewAnimated方法弹出一个全屏的文档预览窗口。
 代码:
 BOOL b=[controller presentPreviewAnimated:YES];
 三、显示菜单
如果你不想直接弹出预览窗口,你可以显示一个选项菜单给用户,由用户选择相应的操作。显示菜单可以使用下列方法:
 –presentOptionsMenuFromRect:inView:animated:
 –presentOptionsMenuFromBarButtonItem:animated:
 –presentOpenInMenuFromRect:inView:animated:
 –presentOpenInMenuFromBarButtonItem:animated:
 这些方法都是类似的,只是显示位置有区别而已。以下代码演示其中一个方法的使用。
 代码:
 CGRect navRect = self.navigationController.navigationBar.frame;
 navRect.size = CGSizeMake(1500.0f, 40.0f);
 [controller presentOptionsMenuFromRect:navRect inView:self.view  animated:YES];
 四、使用委托
 如果你显示一个Document Interaction Controller ,则必需要为delegate属性用指定一个委托。让委托告诉DocumentInteraction Controller如何显示。
 代码:
 controller.delegate =self;
 委托对象需要实现一系列委托方法,最常见的包括:
 –documentInteractionControllerViewControllerForPreview:
 –documentInteractionControllerViewForPreview:
 –documentInteractionControllerRectForPreview:
 这3个方法在用户点击“快速查看”菜单时依次调用。
 代码:
 - (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 
{
     [_controller autorelease];
 }

iOS-UIDocumentInteractionController打开和预览文档的更多相关文章

  1. 【iOS功能实现】之利用UIDocumentInteractionController打开和预览文档

    iOS提供了使用其他app预览文件的支持,这就是Document Interaction Controller.此外,iOS也支持文件关联,允许其他程序调用你的app打开某种文件.而且,从4.2开始, ...

  2. iOS利用UIDocumentInteractionController和Quick Look打开或预览文档

    在App的开发过程中,我们避免不了要打开软件中的文件,例如:Excel文件,Word文件,图片文件等不同格式的文件或者想要通过第三方的App来打开这些文件,那么我们就要用到UIDocumentInte ...

  3. 在其他app里预览文档

    本文转载至 http://www.cocoachina.com/newbie/basic/2013/0515/6212.html iOS中的沙盒可以让平台更加的安全,这也是沙盒给用户带来的最主要好处. ...

  4. C#在线预览文档(word,excel,pdf,txt,png)

    C#在线预览文档(word,excel,pdf,txt,png) 1.预览方式:将word文件转换成html文件然后预览html文件2.预览word文件:需要引入Interop.Microsoft.O ...

  5. C# 基于NPOI+Office COM组件 实现20行代码在线预览文档(word,excel,pdf,txt,png)

    由于项目需要,需要一个在线预览office的功能,小编一开始使用的是微软提供的方法,简单快捷,但是不符合小编开发需求, 就另外用了:将文件转换成html文件然后预览html文件的方法.对微软提供的方法 ...

  6. [SWF]在线预览文档下载

    写本文的缘由:领导有些项目文档需要审阅,网站上的文档只能在线预览,没有提供下载.开始用截屏的方式,可想而知这将会是多大的重复性劳动.所以研究了一下,发现可以曲线救国,所以在这里分享一下. 问题描述:这 ...

  7. 在线预览文档(支持word、excel、ppt、pdf)+在线预览文档html版(转)

    1.首先上网搜索一下有什么解决方案 (1).将文档转换为html,只支持支持office文档 (2).将文档转换为flash,实现类似百度文库的效果,除支持office文档外还支持pdf (1) a. ...

  8. 【微信小程序】下载并预览文档——pdf、word、excel等多种类型

    .wxml文件 <view data-url="https://XXX/upload/zang." data-type="excel" catchtap= ...

  9. Java 如何实现在线预览文档及修改(Office文件)

    测试地址: https://sms.idxkj.cn 用户名:aa 密码:123456

随机推荐

  1. 微信小程序--安装教程

    首先 奉上腾讯官方文档 方便参考:https://mp.weixin.qq.com/debug/wxadoc/design/index.html  个人认为没说啥特别有用的信息(可能是我看的太粗糙了) ...

  2. linux系列目录

    一:linux系列部分  linux系列(一):ls命令 linux系列(二):cd命令 linux系列(三):pwd命令 linux系列(四):mkdir命令 linux系列(五):rm命令 lin ...

  3. 像素迷踪,当Unity的Frame Debugger力不从心时

    http://www.manew.com/thread-92382-1-1.html 从版本5开始,Unity包含了一个全新的可视化帧调试工具,Frame Debugger.该工具能帮你解决很多图形方 ...

  4. package.json 版本号解释

    经常看到package.json中的各种版本号记录 比如 ~ ^ 等.其实是有个规范的.其遵循 semver. 具体的网站为:  http://semver.org/lang/zh-CN/

  5. ssm + ehcache 运行异常

    异常: DEBUG [net.sf.ehcache.CacheManager@295af581] - Checking for update...DEBUG [net.sf.ehcache.Cache ...

  6. 坑:jmeter代理服务器录制脚本出现target controller is configured to "use recording Controller" but no such controller exists...

    配置好代理服务器后,运行代理服务器 run 报错: target controller is configured to "use recording Controller" bu ...

  7. Selenium向iframe富文本框输入内容

    目录 前言 只输入纯文本 通过JS注入HTML代码 前言 在使用Selenium测试一些CMS后台系统时,有时会遇到一些富文本框,如下图所示: 整个富文本编辑器是通过iframe嵌入到网页中的,手动尝 ...

  8. 新建Class文件时,添加作者版权注释声明

    以安装路径C盘为例,各版本路径如下: VS2015:C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTempla ...

  9. 读取本地word 浏览器下载(设置编码格式)

    String filePath = "C:\\word\\报告.doc"; BufferedWriter bos = null; BufferedReader bis = null ...

  10. #C++初学记录(A==B?##高精度)

    Problem Description Give you two numbers A and B, if A is equal to B, you should print "YES&quo ...