DocumentInteraction Controllerl的使用

来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 05:42 点击:
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];
 
}
 
摘自 kmyhy的专栏

    相关新闻>>

      发表评论
      请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
      用户名: 验证码:点击我更换图片
      最新评论 更多>>

      推荐热点

      • Lexical or Preprocessor Issue 'xxx.h
      • ios学习笔记(二)xcode 4.3.2下实现基本交互
      • ios版本的helloworld
      • iphone(object-c) 内存管理(3) 有效的内存管理 前半部分
      • ios学习笔记(一)xcode 4.3.2下创建第一个ios项目
      • IOS类似iphone通讯录TableView的完整demo【附源码】
      • UITableView一些方法
      • [iPhone中级]iPhone团购信息客户端的开发 (二)
      • 如何为Iphone应用创建启动界面
      网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
      Copyright © 2008-2015 计算机技术学习交流网. 版权所有

      豫ICP备11007008号-1