可以快速预览的类型:doc、docx、xls、xlsx、pdf、ppt、pptx、txt、以及在苹果设备压缩的zip文件,其余文件只能显示内容大小名称和格式,然后可以通过左下角按钮分享至其他平台进行显示
如果是通过AFNetWorking下载二进制数据保存至本地,需要配置
manager.responseSerializer.acceptableContentTypes = [NSSet setWithArray:@[@"application/json",
@"text/html",
@"text/json",
@"text/plain",
@"text/javascript",
@"text/xml",
@"image/*",
@"application/pdf",
@"application/msword",
@"application/vnd.ms-powerpoint",
@"application/vnd.ms-excel",
@"application/vnd.openxmlformats-officedocument.presentationml.presentation",
@"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
@"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
@"application/x-rar-compressed",
@"application/zip",
@"application/vnd.android.package-archive",
@"application/octet-stream"]];
// 系统库
import <QuickLook/QuickLook.h>
这里使用的是本地文件
代理: QLPreviewControllerDelegate,QLPreviewControllerDataSource
- (void)loadDocument:(NSString *)docuName {
NSString *path = [[NSBundle mainBundle] pathForResource:docuName ofType:nil];
if (!path) {
return;
}
self.url = [NSURL fileURLWithPath:path];
//
PreviewController *preview = [[PreviewController alloc] initWithNibName:@"PreviewController" bundle:nil];
preview.delegate = self;
preview.dataSource = self;
// [self.navigationController pushViewController:preview animated:YES];
[self presentViewController:preview animated:YES completion:nil];
}
// 显示几份,左右滑动可以查看
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
return 1;
}
// 这里的url,本地获取方法[NSURL fileURLWithPath:path];
// 如果是网络获取的url,https不支持,需要先将文件下载至本地
- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index {
return self.url;
}
如果需要隐藏底部工具栏,自定义QLPreviewController的子类并实现下面的方法,但是下面的方法只能隐藏工具栏,对于按钮处理不了
UIToolbar *toolbar = [self getToolBarFromView:self.view];
toolbar.hidden = YES;
- (UIToolbar *)getToolBarFromView:(UIView *)view {
// Find the QL ToolBar
for (UIView *v in view.subviews) {
if ([v isKindOfClass:[UIToolbar class]]) {
return (UIToolbar *)v;
} else {
UIToolbar *toolBar = [self getToolBarFromView:v];
if (toolBar) {
return toolBar;
}
}
}
return nil;
}