Satyam
Satyam

Reputation: 15894

iOS - Check for Navigation bar

I'm creating a library which will add a view at the bottom of the application (when my library is integrated in application).
I'm using view controller's view's frame parameter to get the size of the view and calculation my library's view frame according and showing it.
The problem is that when navigation bar is there, my view is going still below the actual view visible. So, i want to know whether current view controller is based on navigation controller or not and whether navigation bar is visible in that view or not. how can I find that?

Upvotes: 5

Views: 7610

Answers (3)

Anton Tropashko
Anton Tropashko

Reputation: 5806

Up to date check from a view controller context:

    let navHidden = navigationController?.isNavigationBarHidden ?? true
    if needsCloseButton || navHidden
    {
         // here add an alternative ways to get out since back button is not here, say add a close button somewhere

Upvotes: 0

Cornel Damian
Cornel Damian

Reputation: 733

I'm late with the reply, but for other persons who try to do the same thing (like me :D).

This code may solve your problem:

id nav = [UIApplication sharedApplication].keyWindow.rootViewController;
if ([nav isKindOfClass:[UINavigationController class]]) {
    UINavigationController *navc = (UINavigationController *) nav;
    if(navc.navigationBarHidden) {
        NSLog(@"NOOOO NAV BAR");
    } else {
        NSLog(@"WE HAVE NAV BAR");
    }
}

Upvotes: 11

Michael Dautermann
Michael Dautermann

Reputation: 89509

UINavigationBar inherits from and has all the fine properties and behaviors of UIView and one of these properties is hidden.

So for your view, if you can get a handle to your navigation bar, all you need to do is check to see if hidden is YES or NO.


one way to do this would be to have a UINavigationController property or accessor (setter & getter) for your library so whoever makes use of the library can set the navigation controller and/or bar on your library's behalf.

Upvotes: 2

Related Questions