美文网首页
关于UIDocumentInteractionControlle

关于UIDocumentInteractionControlle

作者: 激动的厨师 | 来源:发表于2018-12-20 11:14 被阅读0次

关于UIDocumentInteractionController

    UIDocumentInteractionController是苹果很早就有的一个很强大的文档阅读,预览,以及分享到第三方的阅读器。
   最近公司要求做一个文档下载查看功能,我上网查了下资料,就用到了UIDocumentInteractionController,用起来也很简单:

@interface WenDangDetailVC
@property (nonatomic ,strong)UIDocumentInteractionController *document;
@end

- (void)onLookBtn{//查看
    if (self.model.isLocal) {
        
        NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject];
        NSString *path = [cachesPath stringByAppendingPathComponent:self.model.FFileUrl];

        self.document = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:path]];

        self.document.delegate = self;
        
        [self.document presentPreviewAnimated:YES];
    
    }else{
        NSURL* url = [[NSURL alloc]initWithString:self.model.FFileUrl];
        [[UIApplication sharedApplication] openURL:url];
    }
}

#pragma mark --UIDocumentInteractionControllerDelegate
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller {
    
    return self;
}

   需要注意要实现UIDocumentInteractionControllerDelegate这个代理
   这样就可以阅读已经下载的文档了,但是,但是,我发现阅读界面导航栏不能修改!这个阅读器是modal上一个QLPreviewController,但是我们修改不了他的导航栏,很奇怪。如图:

image.png

   怎么办呢?我想到重写presentViewController方法,在这里获取到QLPreviewController来设置导航栏,但是还是没用,囧。
   最后还是解决了,用的是父子控制器,在presentViewController获取到QLPreviewController后:

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion{
    LookWenDangVC *vc = [[LookWenDangVC alloc]initWihtVC:viewControllerToPresent model:self.model];
    [self.navigationController pushViewController:vc animated:true];
}

在LookWenDangVC中:

@implementation LookWenDangVC
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = self.model.FName;
    self.navigationItem.leftBarButtonItem = BACK_BUTTON;
    UIButton *rightBtn = [SFButton RightImageButtonItem:@"share_icon"];//
    [rightBtn addTarget:self action:@selector(share) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    
    [self addChildViewController:self.detailVC];
    [self.view addSubview:self.detailVC.view];
    [self.detailVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left);
        make.right.mas_equalTo(self.view.mas_right);
        make.top.mas_equalTo(self.view.mas_top);
        make.bottom.mas_equalTo(self.view.mas_bottom);
    }];
}

这样才实现导航栏的统一如图:


image.png

相关文章

  • 关于UIDocumentInteractionControlle

    关于UIDocumentInteractionController     UIDocumentInteracti...

  • 利用UIDocumentInteractionControlle

    /** txtg格式乱码问题解决方法 */ 参考链接:http://blog.163.com/lxl_dml/bl...

  • 使用UIDocumentInteractionControlle

    背景一: 在app中需要打开类似于 word pdf ppt 等等文件 做一个预览背景二: 所有文件都是进行的本...

  • 通过UIDocumentInteractionControlle

    前言 朋友分享推荐给我一本PDF格式的史蒂夫•乔布斯传,阅读了几篇,很受感触,于是想把他分享给大家欣赏阅读。早起闲...

  • 使用UIDocumentInteractionControlle

    引言:iOS对浏览文件提供了方便的SDK,让开发者调用实现各自的需求,之前利用UIWebView直接加载本地或者网...

  • 使用UIDocumentInteractionControlle

    这次做的项目中需要分享图片到Instagram,于是看了下Instagram的官方文档,要分享图片到Instagr...

  • 关于关于关于

    他们爱他们自己,不爱你 他们爱你是他们的母亲妻子女儿姐妹 他们不爱你 直到你死的时候,爱才产生,与遗忘同时 那也不...

  • 光明人生

    关于出生 关于成长 关于求学 关于青春期 关于恋爱 关于择业 关于婚姻 关于养生 关于家庭 关于人际 关于教子 关...

  • 「梦雅的简动力」打卡计时65天

    * 关于人生 * 关于梦想 * 关于方向 * 关于创业 * 关于投资 * 关于成败 * 关于个性 * 关于高度 *...

  • 关于

    关于两个人? 关于100步? 关于回头? 关于深情? 关于家庭? 关于孩子? 关于成长? 关于伤痛? 关于怀抱? ...

网友评论

      本文标题:关于UIDocumentInteractionControlle

      本文链接:https://www.haomeiwen.com/subject/iuaekqtx.html