QLPreviewController的作用就是快速查看文件,包括word文档,pdf,图片,mp3等音视频文件,而且这里有一个功能很强大,那就是上一篇中说的分享,可以把手机中所有app拉起来进行文件分享的,前提是先打开这个文件,所用到的头文件:

#import <QuickLook/QuickLook.h>

代理协议

<QLPreviewControllerDataSource,QLPreviewControllerDelegate>

点击按钮时创建QLPreviewController

QLPreviewController *previewController = [[QLPreviewController alloc] init];
previewController.dataSource = self;
previewController.delegate = self;
previewController.currentPreviewItemIndex = 0;

[self presentViewController:previewController animated:YES completion:nil];

代理方法中使用:

#pragma mark - QLPreviewControllerDelegate
-(CGRect)previewController:(QLPreviewController *)controller frameForPreviewItem:(id<QLPreviewItem>)item inSourceView:(UIView *__autoreleasing *)view
{
//提供变焦的开始rect,扩展到全屏
return CGRectMake(60, 200, 200, 200);
}

- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)previewController{
return 1;
}

- (id)previewController:(QLPreviewController *)previewController previewItemAtIndex:(NSInteger)idx{

NSString *pathStr=[[NSBundle mainBundle]pathForResource:@"iOS面试题" ofType:@"docx"];
NSURL *fileURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@",pathStr]];

return fileURL;

}

博主这里只是简单说下使用方法,需要深入了解的请自行google,代码下载地址:​​https://github.com/codeliu6572/QLPreviewController​