Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 876
Satyam Avatar asked Feb 21 '12 06:02

Satyam


People also ask

How do I change my navigation bar on iPhone 12?

A user changes the navigation bar's style, or UIBarStyle , by tapping the “Style” button to the left of the main page.


2 Answers

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");
    }
}
like image 127
Cornel Damian Avatar answered Oct 27 '22 01:10

Cornel Damian


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.

like image 39
Michael Dautermann Avatar answered Oct 26 '22 23:10

Michael Dautermann