【iOS功能实现】之利用UIDocumentInteractionController打开和预览文档
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打开和预览文档的更多相关文章
- iOS利用UIDocumentInteractionController和Quick Look打开或预览文档
在App的开发过程中,我们避免不了要打开软件中的文件,例如:Excel文件,Word文件,图片文件等不同格式的文件或者想要通过第三方的App来打开这些文件,那么我们就要用到UIDocumentInte ...
- iOS-UIDocumentInteractionController打开和预览文档
iOS提供了使用其他app预览文件的支持,这就是Document Interaction Controller.此外,iOS也支持文件关联,允许其他程序调用你的app打开某种文件.而且,从4.2开始, ...
- DevExpress的PdfViewer添加工具栏实现PDF打开、预览、保存、打印
场景 Winform控件-DevExpress18下载安装注册以及在VS中使用: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/1 ...
- 使用DevExpress的PdfViewer实现PDF打开、预览、另存为、打印(附源码下载)
场景 Winform控件-DevExpress18下载安装注册以及在VS中使用: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/1 ...
- Android CameraX 打开摄像头预览
目标很简单,用CameraX打开摄像头预览,实时显示在界面上.看看CameraX有没有Google说的那么好用.先按最简单的来,把预览显示出来. 引入依赖 模块gradle的一些配置,使用的Andro ...
- 利用Gulp实现JSDoc 3的文档编写过程中的实时解析和效果预览
### 利用Gulp实现JSDoc 3的文档编写过程中的实时解析和效果预览 http://segmentfault.com/a/1190000002583569
- Java进阶(十九)利用正则表达式批处理含链接内容文档
利用正则表达式批处理含链接内容文档 由于项目需求,自己需要将带有链接的标签去除,例如 <a href="/zhaoyao/17-66.html">头晕</a> ...
- webapi 利用webapiHelp和swagger生成接口文档
webapi 利用webapiHelp和swagger生成接口文档.均依赖xml(需允许项目生成注释xml) webapiHelp:微软技术自带,仅含有模块.方法.请求-相应参数的注释. swagge ...
- Jenkins 利用HTML Publisher plugin实现HTML文档报告展示
利用HTML Publisher plugin实现HTML文档报告展示 by:授客 QQ:1033553122 测试环境 HTML Publisher Plugin 1.1.2 Jenkins2. ...
随机推荐
- Entity Framework做IN查询
开发中遇到的Too high level of nesting for select错误 项目使用了Entity Framework结合Mysql, 遇到了一个非常奇怪的性能问题,一个看起来非常简单的 ...
- 完全卸载VS2005或VS2008的步骤
手动卸载步骤: Visual Studio Express Editions 进入控制面板,运行添加或删除程序 卸载 "MSDN Library for Visual Studio 200 ...
- 常用HTML正则
<?php //HTML a连接正则 $str = ''; $isMatched = preg_match('/<a.*?[^<]>.*?<\/a>/', $str ...
- jQuery Validate 表单验证插件----自定义校验结果样式
一.下载依赖包 网盘下载:https://yunpan.cn/cryvgGGAQ3DSW 访问密码 f224 二.引入依赖包 <script src="../../scripts/j ...
- hdu 2874 Connections between cities [LCA] (lca->rmq)
Connections between cities Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- Linux学习之四——磁盘与文件系统管理
一.一些基本定义 1. superblock:记录此 filesystem 的整体信息,包括inode/block的总量.使用量.剩余量, 以及文件系统的格式与相关信息等:2. inode:记录档案的 ...
- dipole antenna simulation by CST
CST偶极子天线仿真,半波振子天线 一.本文使用CST仿真频率为1GHz的偶极子天线,使用2013版本.仿真的步骤为 1.选择一个CST的天线工程模板 2.设置好默认的单位 3.设置背景的材料(空气腔 ...
- NOIP2014提高组 DAY1 -SilverN
T1 生活大爆炸版石头剪刀布 题目描述 石头剪刀布是常见的猜拳游戏:石头胜剪刀,剪刀胜布,布胜石头.如果两个人出拳一样,则不分胜负.在<生活大爆炸>第二季第8 集中出现了一种石头剪刀布的 ...
- MIT jos 6.828 Fall 2014 训练记录(lab 2)
注: 源代码参见我的github:https://github.com/YaoZengzeng/jos Part1 : Physical Page Management mem_init函数: /*该 ...
- hdu-5834 Magic boy Bi Luo with his excited tree(树形dp)
题目链接: Magic boy Bi Luo with his excited tree Time Limit: 8000/4000 MS (Java/Others) Memory Limit: ...