UIDocumentInteractionController本地查看文件
- 实例化一个UIDocumentInteractionController对象并遵守其delegate
@interface FileReviewController ()
@property (nonatomic, strong) UIDocumentInteractionController *DIController;
@end
NSURL *urlPath = [[NSBundle mainBundle] URLForResource:@"Jobs" withExtension:@"pdf" subdirectory:@"PDF.bundle"];
self.DIController = [UIDocumentInteractionController interactionControllerWithURL:urlPath];
self.DIController.delegate = self;
- 实现delegate
#pragma mark - UIDocumentInteractionControllerDelegate
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller {
return self;
}
- (UIView*)documentInteractionControllerViewForPreview:(UIDocumentInteractionController*)controller {
return self.view;
}
- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController*)controller {
return self.view.frame;
}
- 读取本地文件
[self.DIController presentPreviewAnimated:YES];
UIDocumentInteractionController第三方分享
[self.DIController presentOptionsMenuFromRect:self.view.bounds inView:self.view animated:YES];
显示菜单的方法:
- presentOptionsMenuFromRect:inView:animated: - presentOptionsMenuFromBarButtonItem:animated: - presentOpenInMenuFromRect:inView:animated: - presentOpenInMenuFromBarButtonItem:animated: