iOS系统预览文件但不分享的实用技巧 (iOS10, QLPreviewController)
2017-07-21 14:35
399 查看
苹果系统的文件预览能力对于很多app来说是必要的,但其提供的UI相关api并不是可以定制的,比如需要定制toolbar, navigationbar的情况,直接使用QLPreviewController或者
UIDocumentInteractionController 并不能达到想要的效果。
根据笔者的试验来看,现在 iOS10 QLPreviewController 和 UIDocumentInteractionController一样,都是直接在下面显示一个分享按钮,上面是标题栏。
如何对其UI进行定制呢?
QLPreviewController 作为一个正儿八经的viewcontroller,可以对其进行子类化操作,改变其行为,代码类似这样:
(void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.navigationController.navigationBar.hidden = YES;
self.navigationController.toolbar.hidden = YES;
// custom view demonstrate
UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
topView.backgroundColor = [UIColor redColor];
[self.view addSubview:topView];
}
为何在viewWillLayoutSubviews执行操作呢?
preview过程中可以点击全屏放大缩小,在这个过程中,你会发现此前所做的view操作被恢复了;这里的viewWillLayoutSubviews相当于是一个hook,可以让我们在view改变以后再把他置回来,达到我们想要的效果。
还有另外一种方案,只add QLPreviewController的 view 作为subview,代码类似这样:
MyPreviewViewController *qlVc = [[MyPreviewViewController alloc] init];
qlVc.delegate = self;
qlVc.dataSource = self;
qlVc.view.frame = CGRectMake(0, 100, 300, 300);
[self.view addSubview:qlVc.view];
对于该frame以外的部分则可以由我们来自由定制。
而UIDocumentInteractionController作为一个nsobject对象,产生的新UI要对其操纵所需要的手法可能更加tricky,这里笔者也没有做更多的实践,如果大家有好的思路也请分享给我,谢谢!
对于以前版本(iOS10以前)的QLPreviewController,分享按钮貌似是在右上角的,对其定制的方案讨论有很多,这里贴出链接供大家参考: http://blog.csdn.net/jeffasd/article/details/49662483 https://stackoverflow.com/questions/6957091/qlpreviewcontroller-remove-or-add-uibarbuttonitems http://www.jianshu.com/p/73048dbe6a7d
其思路主要是以下几种:
1. 子类化 ; 2. category, method swizz; 3. 只使用它的view
比我们上面的方案多了一种使用oc runtime的做法;oc中的runtime功能比较强大,有开发者想到这种解决方案也是正常的。
UIDocumentInteractionController 并不能达到想要的效果。
根据笔者的试验来看,现在 iOS10 QLPreviewController 和 UIDocumentInteractionController一样,都是直接在下面显示一个分享按钮,上面是标题栏。
如何对其UI进行定制呢?
QLPreviewController 作为一个正儿八经的viewcontroller,可以对其进行子类化操作,改变其行为,代码类似这样:
(void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.navigationController.navigationBar.hidden = YES;
self.navigationController.toolbar.hidden = YES;
// custom view demonstrate
UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
topView.backgroundColor = [UIColor redColor];
[self.view addSubview:topView];
}
为何在viewWillLayoutSubviews执行操作呢?
preview过程中可以点击全屏放大缩小,在这个过程中,你会发现此前所做的view操作被恢复了;这里的viewWillLayoutSubviews相当于是一个hook,可以让我们在view改变以后再把他置回来,达到我们想要的效果。
还有另外一种方案,只add QLPreviewController的 view 作为subview,代码类似这样:
MyPreviewViewController *qlVc = [[MyPreviewViewController alloc] init];
qlVc.delegate = self;
qlVc.dataSource = self;
qlVc.view.frame = CGRectMake(0, 100, 300, 300);
[self.view addSubview:qlVc.view];
对于该frame以外的部分则可以由我们来自由定制。
而UIDocumentInteractionController作为一个nsobject对象,产生的新UI要对其操纵所需要的手法可能更加tricky,这里笔者也没有做更多的实践,如果大家有好的思路也请分享给我,谢谢!
对于以前版本(iOS10以前)的QLPreviewController,分享按钮貌似是在右上角的,对其定制的方案讨论有很多,这里贴出链接供大家参考: http://blog.csdn.net/jeffasd/article/details/49662483 https://stackoverflow.com/questions/6957091/qlpreviewcontroller-remove-or-add-uibarbuttonitems http://www.jianshu.com/p/73048dbe6a7d
其思路主要是以下几种:
1. 子类化 ; 2. category, method swizz; 3. 只使用它的view
比我们上面的方案多了一种使用oc runtime的做法;oc中的runtime功能比较强大,有开发者想到这种解决方案也是正常的。
相关文章推荐
- iOS开发 - 打开文件后进行文件分享(QLPreviewController)
- ios 预览文件-QLPreviewController用法
- Vickate_iOS_文件预览QLPreviewController(pdf,excel,word等)
- iOS 使用QLPreviewController预览本地和网络文件
- ios-文件预览-QLPreViewController
- ios开发 关于在app中预览pdf,word,excel时,使用QLPreviewController还是UIWebView
- IOS 使用QLPreviewController浏览PDF WORD等文件
- QLPreviewController 预览文件
- iOS利用QLPreviewController显示PDF,word,execl,txt等格式的文件
- QLPreviewController来预览文件
- 实用技巧:在Li 4000 nux系统中查找文件的方法
- iOS 两种系统分享(配Demo下载)UIActivityViewController 和 SLComposeViewController
- IOS 打开预览pdf、ppt、excel、word、tet、rtf、csv格式的文件,微信文件分享
- iOS开发技巧--禁止系统头文件被不小心修改
- iOS-75-分享Xcode使用技巧(兼容iOS10、iPhone刷机固件、Xcode各版本、内存泄漏检测)
- iOS指南系列:使用QLPreviewController浏览文档
- XP实用技巧:恢复被破坏的系统文件
- iOS QLPreviewController(Quick Look)快速浏览jpg,PDF,world等
- QLPreViewController的初步实用
- 实用技巧:Linux系统下文件权限设置方法