Check if tabBar is displayed in iOS app.

I am working on an iOS application that has a UITabBarController for displaying a TabBar. In some cases, I present a full screen modalView that hides a tabBar.

I want to determine when my tabBar is visible to the user. Is there a way to check automatically when a tabBar is displayed or not?

I tried:

But this really does not work, because the tabBar is not actually hidden.

if ([[[appdelegate tabBarController] tabBar] isHidden]) { NSLog(@"tabBar IS HIDDEN"); } else { NSLog(@"tabBar IS VISIBLE"); } 

I am writing this code in BaseViewController, which is a superclass of my modal view and other views of my project.

Thanks.

+6
source share
6 answers

Checking this [[[self tabBarController] tabBar] isHidden] fine, but in one case it will fail. If you don't have a tab bar in this view (in general), then [self tabBarController] returns nil , so calling isHidden will return NO, which is true, but you should detect this situation in another case. It is not hidden, but it does not exit it, except that you must add [self tabBarController] != nil . So basically:

 if([self tabBarController] && ![[[self tabBarController] tabBar] isHidden]){ //is visible } else { //is not visible or do not exists so is not visible } 
+7
source

You can try this

 if ([[[self tabBarController] tabBar] isHidden]){ NSLog(@"tabBar IS HIDDEN"); } else { NSLog(@"tabBar IS VISIBLE"); } 
+4
source

Answer in Swift 3/4 +

 if let tabBarController = self.tabBarController, !tabBarController.tabBar.isHidden { // tabBar is visible } else { // tabBar either is not visible or does not exist } 
+1
source

This is probably the easiest way: (if you are not playing directly with the views)

The ViewController to be redirected to the navigationController has the hidesBottomBarWhenPushed property. Just check if it is YES in the view controller, and you know if the scoreboard is hidden or not.

0
source

I use this in Swift:

 tabBarController?.tabBar.isHidden ?? true 

I use it to find the height of the tab bar:

 var tabBarHeight: CGFloat { if tabBarController?.tabBar.isHidden ?? true { return 0 } return tabBarController?.tabBar.bounds.size.height ?? 0 } 
0
source

Check the window tabBar property. This property is nil when it UIView not displayed in a UIView .

 if((BOOL)[[[self tabBarController] tabBar] window]) { // visible } else { // not visible } 
-1
source

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


All Articles