UIDocumentInteractionController 的使用

来源:互联网 发布:淘宝电脑主机便宜 编辑:程序博客网 时间:2024/06/10 01:22
////  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
阅读全文
0 0
原创粉丝点击