Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iphone: Is it possible to hide the TabBar? (Pre-iOS 8)

I have an application that uses a UITabBarController to switch between modes. When in a certain mode, I'd like to hide the tab bar until the steps of that mode have been completed. Note that I'm not using a navigation controller so I can't use the setHidesBottomBarWhenPushed method on the navigation controller to hide the tab bar.

Prior to iOS 8, When I attempt to hide the tarbar using:

self.tabBarController.tabBar.hidden = YES 

the tab bar goes away, but it leaves a 50 pixel blank area at the bottom of the screen where the tab bar used to be. I can't seem to figure out how to fill that area. Anything in the UI that is in that area is clipped and cannot be seen.

Any ideas if this is even possible? I'd really like to stay away from the navigation controller.

like image 656
Steve Avatar asked Dec 30 '09 20:12

Steve


People also ask

What is tab bar in IOS?

The tab bar interface displays tabs at the bottom of the window for selecting between the different modes and for displaying the views for that mode. This class is generally used as-is, but may also be subclassed. Each tab of a tab bar controller interface is associated with a custom view controller.

How do I get rid of the tab bar in Swift?

If you don't want that behavior, you should set hidesBottomBarWhenPushed to true where applicable. This will hide the tab bar along with any toolbars you had showing, but only when a view controller is pushed onto the navigation stack. This allows you to show the tab bar at first, then hide it when you need more room.

How do I hide the bottom navigation bar in Swift?

Way 1: Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.


1 Answers

Here's my code for that:

This is, of course, mucking with the goings on in the controller's view hierarchy. It could change/break. This uses defined APIs, so Apple won't care, but they won't care about breaking your code, either.

- (void)hideTabBar {   UITabBar *tabBar = self.tabBarController.tabBar;   UIView *parent = tabBar.superview; // UILayoutContainerView   UIView *content = [parent.subviews objectAtIndex:0];  // UITransitionView   UIView *window = parent.superview;    [UIView animateWithDuration:0.5                    animations:^{                      CGRect tabFrame = tabBar.frame;                      tabFrame.origin.y = CGRectGetMaxY(window.bounds);                      tabBar.frame = tabFrame;                      content.frame = window.bounds;                    }];    // 1 }  - (void)showTabBar {   UITabBar *tabBar = self.tabBarController.tabBar;   UIView *parent = tabBar.superview; // UILayoutContainerView   UIView *content = [parent.subviews objectAtIndex:0];  // UITransitionView   UIView *window = parent.superview;    [UIView animateWithDuration:0.5                    animations:^{                      CGRect tabFrame = tabBar.frame;                      tabFrame.origin.y = CGRectGetMaxY(window.bounds) - CGRectGetHeight(tabBar.frame);                      tabBar.frame = tabFrame;                       CGRect contentFrame = content.frame;                      contentFrame.size.height -= tabFrame.size.height;                    }];    // 2 } 

Edit: An anonymous user has suggested the following addition for 7.0 (i have not tested this, and could not say whether it is a workaround or an ideal implementation):

// 1. To Hide the black line in IOS7 only, this extra bit is required if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {     [self.tabBarController.tabBar setTranslucent:YES]; }    // 2. For IOS 7 only if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {     [self.tabBarController.tabBar setTranslucent:NO]; } 

Edit: Entirely untested in 8.x and likely lacking in some layouts.

like image 106
bshirley Avatar answered Sep 23 '22 00:09

bshirley