//
// ViewController.m
// pdfViewer
//
// Created by Johnay on 17/9/28.
// Copyright © 2017年 Johnay. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()<UIDocumentInteractionControllerDelegate>
@property (nonatomic, strong) UIDocumentInteractionController *document;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
NSURL *url = [[NSBundle mainBundle] URLForResource:@"pdffile" withExtension:@"pdf"];
// NSString *docu = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
// NSString *filePath = [docu stringByAppendingPathComponent:@"004.png"];
// NSURL *url = [NSURL fileURLWithPath:filePath];
self.document = [UIDocumentInteractionController interactionControllerWithURL:url];
self.document.delegate = self;
// 不展示可选操作
// [self.document presentOpenInMenuFromRect:self.view.bounds inView:self.view animated:YES];
// 展示可选操作
// 可结合代理方法documentInteractionControllerViewControllerForPreview:显示预览
[self.document presentOptionsMenuFromRect:self.view.bounds inView:self.view animated:YES];
}
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller {
return self;
}
/**
* 文件分享面板退出时调用
*/
- (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller {
NSLog(@"dismiss");
}
/**
* 文件分享面板弹出的时候调用
*/
- (void)documentInteractionControllerWillPresentOpenInMenu:(UIDocumentInteractionController *)controller {
NSLog(@"WillPresentOpenInMenu");
}
/**
* 当选择一个文件分享App的时候调用
*/
- (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(nullable NSString *)application {
NSLog(@"begin send : %@", application);
}
@end
UIDocumentInteractionController的使用
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 此时,还有多少人,想要成为一位作家? 就像歌者是为了表达自我,抒发灵魂之弦音,作者是用语言文字书写了自我世界的乌托...