4

I currently have a UIView that programmatically has an embedded QLPreviewController in it. I need to get rid of the default navigator bar that the QLPreviewController has when the document/url is loaded. Is there a way to do this?

Currently, I've tried subclassing QLPreviewController and in the viewDidAppear set self.navigationController!.navigationBarHidden = true. But this doesn't work.

Sorry if this is a dupe question - I've been looking online the last few days and couldn't find a concrete answer with iOS 8/9.

Vvk
  • 4,031
  • 29
  • 51
GoshDangitBobby
  • 243
  • 1
  • 10

4 Answers4

2

I Solve this problem by using addChildViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupPreviewController];
}

- (void)setupPreviewController {
    self.previewController = [[QLPreviewController alloc] init];
    [self addChildViewController:self.previewController];
    [self.view addSubview:self.previewController.view];

    //do autolayout
    [self.previewController.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.view);
    }];
    self.navigationController.navigationBarHidden = YES;
}
violethill
  • 57
  • 5
0

Same thing apply in viewWillAppear and in viewDidLoad methods self.navigationController!.navigationBarHidden = true

i hope this will help

Bhaskar Cm
  • 38
  • 3
0

It does appear to be possible. After inspecting the view hierarchy at runtime I found that the nav bar you see is actually a subview of the View Controller's view. The code below will remove it; however, it will not stay gone and it does not appear that there is any sanctioned way to modify the UI elements of this class. Any modification of this class will be a fragile hack and I'd recommend finding something less locked down to customize.

class MyPreviewViewController: QLPreviewController {
    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()

        if let subviewsWithNav = self.view.subviews.first?.subviews {
            for view in subviewsWithNav {
                if let navbar = view as? UINavigationBar {
                    navbar.isHidden = true
                }
            }
        }
    }
}
Eric Mentele
  • 864
  • 9
  • 16
0

This worked for me:

class CustomQLPreview: QLPreviewController {
    ...        
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()    
        navigationController?.setNavigationBarHidden(true, animated: false)          
    }
}
MrAn3
  • 1,335
  • 17
  • 23