Quicklook / QLPreviewController,与iOS 8的一些问题,但一切适用于iOS 7.1

我正在使用QuickLook查看PDF文件。

它在iOS 7.1中正常工作,但iOS 8 GM发生了一些问题。

图片比文字好,我想告诉你的问题:

iOS 7.1的Xcode 6(工作正常)

使用QuickLook进行转换(无失败)

转换QuickLook iOS 7.1

页面滚动,导航栏隐藏得很好

页面滚动QuickLook iOS 7.1

————————————————– ————————

而现在,iOS 8 GM与Xcode 6

使用QuickLook进行过渡…

转换QuickLook iOS 8 GM

页面滚动,navigationBar不隐藏,页面指示器隐藏在NavigationBar后面

页面滚动QuickLook iOS 8 GM

与iPhone模拟器,iPad模拟器,iPhone设备和iPad设备同样的问题。

你可以在这里看到我的源代码:

- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)previewController { NSInteger numToPreview = 0; if (currentSection == CVSectionConvocations) numToPreview = self.convocation.convocations.count; else if (currentSection == CVSectionAttachments) numToPreview = self.convocation.attachements.count; return numToPreview; } - (id)previewController:(QLPreviewController *)previewController previewItemAtIndex:(NSInteger)idx { PDF *pdf; if (currentSection == CVSectionConvocations) pdf = self.convocation.convocations[idx]; else if (currentSection == CVSectionAttachments) pdf = self.convocation.attachements[idx]; return [pdf path]; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { // determine section currentSection = (indexPath.section == 0 ? CVSectionConvocations : CVSectionAttachments); PDF *pdf; if (currentSection == CVSectionConvocations) pdf = self.convocation.convocations[indexPath.row]; else if (currentSection == CVSectionAttachments) pdf = self.convocation.attachements[indexPath.row]; if ([pdf isStored]) { QLPreviewController *previewController = [[QLPreviewController alloc] init]; previewController.dataSource = self; previewController.delegate = self; previewController.currentPreviewItemIndex = indexPath.row; [[self navigationController] pushViewController:previewController animated:YES]; } else { [self displayMessage:@"Document not found" title:@"Oups !"]; } } 

谢谢你的帮助 ;)

我在转换过程中遇到了同样的问题。 我的解决scheme是将previewController存储在属性中,并在我的呈现视图控制器中的viewDidLoad中初始化一次。

我也必须设置currentPreviewItemIndex等于0每次我推预览控制器,虽然我只显示一个文件的时间。 如果我没有设置值,zip文件默认不打开,预览控制器显示“显示内容”button,而是打开一个新的预览控制器遭受同样的过渡问题。

我仍然试图解决不隐藏的导航栏问题。 在苹果示例项目中,一切正常。 看来,模态地呈现导航控制器导致我的项目中的问题。

编辑:

这对我来说绝对是一个错误。 导航栏的问题只有在导航控制器呈现为模态时才会出现。 在我看来,预览控制器创build一个新的导航控制器,也是一个新的导航栏。 这个隐藏在托pipe导航控制器的导航栏下。 这个截图很好地显示了这个问题: 在这里输入图像说明

蓝色突出显示的栏是self.navigationBar,蓝色框架属于预览控制器。 只有当导航控制器呈现为模态时,才会发生这种情况。

我的解决方法是将我的视图控制器设置为导航控制器委托,并在预览控制器被推入时立即隐藏导航栏。 我只在iOS 8.0和8.1上testing我的代码。

 - (void)viewDidLoad { [super viewDidLoad]; self.previewController = [[QLPreviewController alloc] init]; self.previewController.delegate = self; self.previewController.dataSource = self; self.navigationController.delegate = self; } -(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { // Workaround: // If the previewController is pushed to a navigation controller which is presented modal, it appears that the preview controller adds a second navigation bar (and navigation controller). // This results in a UI glitch that one nav bar is always visible. To prevent this we hide our navigation bar so that only the one owned by the preview controller is visible. // Note that this only happends if the navigation controller is presented modal, thus it seems to be an iOS bug. if (viewController == self.previewController) { [self.navigationController setNavigationBarHidden:YES animated:YES]; } } 

我最近已经能够解决背景问题(animation仍然不稳定)。

为了解决“黑色背景”问题,我设置了导航控制器视图的自定义背景色。 当返回到我的视图控制器时,确保将原始背景颜色恢复为零。

 - (void)viewWillApear:(BOOL)animated { [super viewWillApear:animated]; self.navigationController.view.backgroundColor = nil; // Optional - In order to ease the animation bug self.view.alpha = 1.0; } - (void)viewWillDissapear:(BOOL)animated { [super viewWillDissapear:animated]; self.navigationController.view.backgroundColor = [UIColor whiteColor]; // Optional - In order to ease the animation bug [UIView animateWithDuration:0.35 animations:^{ self.view.alpha = 0.0; }]; } 

这段代码应该去你的视图控制器从你推QLPreviewController。

这个解决scheme绝对是最好的,但希望它有帮助!