The main problem is that when you try to set the transparency of the navigation bar, you have not yet pressed the preview controller in the navigation stack. At this point, the preview controller is selected and created, but its view is not loaded or added to the view hierarchy, and the value of previewer.navigationController is zero. The value of self.navigationController not zero at this point, but the translucency property that you set here will be overwritten as a side effect of clicking the preview controller. The easiest way to get the effect you want is to reorder the instructions, for example:
[self.navigationController pushViewController:previewer animated:YES]; self.navigationController.navigationBar.translucent = NO;
Please note that with the translucency of the navigation bar set to NO, the previewed content will start under the navigation bar, which is probably not what you want. The easiest way to get around this problem is to set the transparency property after the view controller appears on the screen. You can do this by subclassing QLPreviewController:
@interface PreviewController : QLPreviewController @end @implementation PreviewController - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; self.navigationController.navigationBar.translucent = NO; }
Note that itβs more difficult when you present the preview controller in different ways (rather than pushing it on the navigation stack). In this case, there is no navigation controller to access the navigation bar, and you need to rely on the internal hierarchy of the QLPreviewController views. The following code works in iOS7, but may be corrupted in a later version:
[self presentViewController:previewController animated:YES completion:^{ UIView *view = [[[previewController.view.subviews lastObject] subviews] lastObject]; if ([view isKindOfClass:[UINavigationBar class]]) { ((UINavigationBar *)view).translucent = NO; } }];
hverlind
source share