RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
iOS文件预览UIDocumentInteractionController

在应用开发中,有时候需要预览文档和视频,使用 UIDocumentInteractionController 来预览文件非常方便,支持的格式比较多,比如 docx、xlsx、pdf、mov、mp4、jpg、png 等等都可以。具体代码如下:

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名注册雅安服务器托管、营销软件、网站建设、霍邱网站维护、网站推广。

@interface ViewController () 
 
@property(nonatomic,strong) UIDocumentInteractionController * documentVC;
 
@end
 
@implementation ViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"第 7 章 Mach-O 文件格式解析" ofType:@"docx"];
    NSURL *url = [NSURL fileURLWithPath:path];
    
    self.documentVC = [UIDocumentInteractionController interactionControllerWithURL:url];
    self.documentVC.delegate = self;
    
    dispatch_async(dispatch_get_main_queue(), ^{
        BOOL b = [self.documentVC presentPreviewAnimated:YES];
    });
}
 
#pragma mark 代理方法
//为快速预览指定控制器
- (UIViewController*)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController*)controller
{
    NSLog(@"%@",NSStringFromSelector(_cmd));
    return self;
}
 
//为快速预览指定View
- (UIView*)documentInteractionControllerViewForPreview:(UIDocumentInteractionController*)controller
{
    NSLog(@"%@",NSStringFromSelector(_cmd));
    return self.view;
}
 
//为快速预览指定显示范围
- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController*)controller
{
    NSLog(@"%@",NSStringFromSelector(_cmd));
    //    return self.view.frame;
    return CGRectMake(0, 0, self.view.frame.size.width, 300);
}
 
@end

效果如下图,点击 Done 就能回到主界面。

iOS 文件预览 UIDocumentInteractionController

原文地址:https://www.exchen.net/ios-%E6%96%87%E4%BB%B6%E9%A2%84%E8%A7%88-uidocumentinteractioncontroller.html


文章题目:iOS文件预览UIDocumentInteractionController
当前URL:http://sczitong.cn/article/pedjog.html