Quicklook / QLPreviewController, some problems with iOS 8, but everything works with iOS 7.1

I am working with QuickLook to view PDF files.

It works correctly in iOS 7.1, but some problems arise with iOS 8 GM.

Pictures are better than words, I want to show you problems:

iOS 7.1 Xcode 6 (works great)

Switching from QuickLook (no crash)

Transition QuickLook iOS 7.1

Scrolling page, navigation bar is well hidden

Page scroll QuickLook iOS 7.1

-------------------------------------------- ------ ------------------------

And now iOS 8 GM with Xcode 6

Switching from QuickLook ...

Transition QuickLook iOS 8 GM

Scrolling the page, the navigation bar does not hide, the page indicator hides behind the navigation panel

Page scroll QuickLook iOS 8 GM

Same issue with iPhone simulator, iPad simulator, iPhone device and iPad device.

Here you can see my source code:

- (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 !"]; } } 

Thank you for your help;)

+7
ios objective-c quicklook
source share
2 answers

I had the same problem with the transition. My solution was to save the previewController in the property and initialize it once in viewDidLoad in my view controller view.

I also needed to set currentPreviewItemIndex to 0 every time I click previewcontroller, although at that time I only show one file. If I do not set the value, then the zip files do not open by default, and the preview controller shows the "Show contents" button, instead a new preview controller opens, faced with the same transition problem.

I am still trying to fix a hidden navigation bar issue. In the apple sample project, everything works fine. It seems that the modal representation of the navigation controller is causing a problem in my project.

EDIT:

This definitely seems like a mistake to me. The problem with the navigation bar appears only if the navigation controller is presented as modal. It seems to me that the preview controller creates a new navigation controller, as well as a new navigation panel. This one is hidden under the navigation bar of the hosting navigation controller. This screenshot shows the problem pretty well: enter image description here

The blue highlighted panel is self.navigationBar, and the blue frame is in the preview controller. Again this only happens if the navigation controller is modal.

My workaround is to set my view controller as a delegate to the navigation managers and hide the navigation bar as soon as the preview controller is clicked. I only tested my code on iOS 8.0 and 8.1.

 - (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]; } } 
+2
source share

Recently, I was able to fix a background error (the animation is still intermittent).

To fix the "black background" problem, I set the custom background color as a navigation controller when clicked. Returning to the view controller, I will return to the original background color at zero.

 - (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; }]; } 

This code should go to your view controller from which you click QLPreviewController.

This solution certainly hacked it, but hope it helps!

+1
source share

All Articles