Search code examples
iosquicklookarquicklook

How to hide top bar on QLPreviewController by default


I am presenting a QuickLook preview controller like so:

 QLPreviewController *qlController = [[QLPreviewController alloc] init];
    qlController.dataSource = self;
    qlController.delegate = self;
    dispatch_async(dispatch_get_main_queue(), ^{
        [rootVC presentViewController:qlController animated:NO completion:nil];
    });

I'm passing it a usdz preview item. As soon as the item loads in the top bar it disappears but the effect is jarring.

Is there any way to hide this top bar (highlighted in yellow) by default so it never shows up?

enter image description here


Solution

  • Yes you can, but after presenting QLPreviewController. Following code will works to hide navigation bar, but after few moment.

    Objective-C:

    [self presentViewController:qlController animated:true completion:^{
        UINavigationBar *navBar = [[[[[qlController view] subviews] firstObject] subviews] objectAtIndex:1];
        [navBar setHidden:true];
    }];
    

    Swift:

    self.present(qlController, animated: true) {
        if let navigationBar = qlController.view.subviews.first?.subviews[1] as? UINavigationBar {
            navigationBar.isHidden = true
        }
    }