IOS - check the navigation bar

I am creating a library that will add a view at the bottom of the application (when my library is integrated into the application).
I use the frame view view view parameter to get the size of the view and calculate the frame of the library view and show it.
The problem is that when there is a navigation bar, my view is still below the visible actual view. So, I want to know if the current view controller is based on the navigation controller or not, and whether the navigation bar is visible in this view or not. how can i find this?

+4
source share
3 answers

UINavigationBar inherits and has all the wonderful properties and behavior of the UIView , and one of these properties is hidden .

So, for your presentation, if you can get a handle to the navigation bar, you just need to check if there are hidden YES or NO .


one way to do this would be to have a UINavigationController or accessor (setter and getter) property for your library so that anyone using the library can set a navigation controller and / or panel for your library name.

+2
source

I was late with the answer, but for other people who are trying to do the same (for example, I: 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"); } } 
+10
source

Actual check from the context of the view controller:

  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 
0
source

Source: https://habr.com/ru/post/1397552/


All Articles