Iphone: Can I hide a TabBar? (Pre-iOS 8)

I have an application that uses a UITabBarController to switch between modes. When in a certain mode, I would like to hide the tab bar until the steps of this mode are completed. Note that I am not using a navigation controller, so I cannot use the setHidesBottomBarWhenPushed method on the navigation controller to hide the tab bar.

Prior to iOS 8, when I try to hide the tarbar using:

 self.tabBarController.tabBar.hidden = YES 

the tab bar leaves, but it leaves a blank area of ​​50 pixels at the bottom of the screen, where the tab bar used to be. I can’t figure out how to fill this area. Everything that is in the user interface that is in this area is cropped and not displayed.

Any ideas if possible? I really would like to stay away from the navigation controller.

+34
ios objective-c iphone uitabbarcontroller
Dec 30 '09 at 20:06
source share
16 answers

Here is my code for this:

This, of course, is a mistake related to the ideas in the controller presentation hierarchy. It may change / break. This uses certain APIs, so Apple doesn't care, but they don't care about code breaking.

 - (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 suggested the following add-on for 7.0 (I did not test this and could not say if this 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 : completely untested in 8.x and probably missing from some layouts.

+37
Feb 23 2018-12-12T00:
source share

Like Steve, I did not find a clean way to do this (although Apple Photopicker does something similar). Here is what I did:

  if (systemAction) { // Reveal tab bar back CGRect bounds = [[UIScreen mainScreen] bounds]; CGRect tabBarFrame = self.tabBarController.tabBar.frame; self.tabBarController.view.frame = CGRectMake(0,0,bounds.size.width,bounds.size.height); self.toolBar.hidden = YES; systemAction = NO; } else { //hide tab bar CGRect bounds = [[UIScreen mainScreen] bounds]; CGRect tabBarFrame = self.tabBarController.tabBar.frame; CGRect navigationBarFrame = self.navigationController.navigationBar.frame; self.tabBarController.view.frame = CGRectMake(0,0,bounds.size.width,bounds.size.height+tabBarFrame.size.height); self.toolBar.hidden = NO; CGRect frame = self.toolBar.frame; frame.origin.y = bounds.size.height - frame.size.height - navigationBarFrame.size.height; self.toolBar.frame = frame; systemAction = YES; } 

What he does is click down so that I can display the toolbar (rather than hide it). Obviously, this is only for the "root view" on the control panel + navigation controller. For any subsequent views, you can set "hidesBottomBarWhenPushed" to the viewcontroller you call.

+9
Dec 17 '10 at 12:10
source share

I tried several of the solutions above, but not a joy in iOS 8. I believe that setting in viewWillAppear works for me. It should work in iOS 7 since the extended LayoutIncludesOpaqueBars has been expanded.

  self.extendedLayoutIncludesOpaqueBars = true self.tabBarController?.tabBar.isHidden = true self.tabBarController?.tabBar.isOpaque = true 

and if you need to enable tabBars again when you leave, to use the following in viewWillDisappear.

  self.tabBarController?.tabBar.isHidden = false self.tabBarController?.tabBar.isOpaque = false 

I use this to return from the transition to keep the TabBar hidden. Do not use it in a button action, but if I, like me, you don’t find anything above, this may be the basis for a programmable solution.

+8
Feb 08 '15 at 19:57
source share

It's a bit late that day, but of all the answers to the question I flew through that day, this is the one that worked best for me.

How to hide uitabbarcontroller

 // Method call [self hideTabBar:self.tabBarController]; 



 // Method implementations - (void)hideTabBar:(UITabBarController *) tabbarcontroller { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; for(UIView *view in tabbarcontroller.view.subviews) { if([view isKindOfClass:[UITabBar class]]) { [view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)]; } else { [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)]; } } [UIView commitAnimations]; } - (void)showTabBar:(UITabBarController *) tabbarcontroller { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; for(UIView *view in tabbarcontroller.view.subviews) { NSLog(@"%@", view); if([view isKindOfClass:[UITabBar class]]) { [view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)]; } else { [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)]; } } [UIView commitAnimations]; } 
+4
Oct 24
source share

I use only this single line to achieve this. I use the prepareForSegue method before displaying a view controller that has a tab bar.

 -(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if([segue.identifier isEqualToString:@"showLogin"]){ [segue.destinationViewController setHidesBottomBarWhenPushed:YES]; } } 
+4
Aug 17 '14 at 6:10
source share

I worked in almost the same case, actually used the code http://www.developers-life.com/hide-uitabbarcontrolleruitabbar-with-animation.html and made it better according to my needs, this could help others too .

I use UISplitViewController as the root view controller, and its detailed part is UITabBarController, I needed to hide the panel in portrait mode:

 // In UITabBarController custom implementation add following method, // this method is all that will do the trick, just call this method // whenever tabbar needs to be hidden/shown - (void) hidetabbar:(NSNumber*)isHidden { UITabBarController *tabBarController=self; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; CGRect tabbarFrame=CGRectZero; for(UIView *theView in tabBarController.view.subviews) { //NSLog(@"%@", view); if([theView isKindOfClass:[UITabBar class]]) { tabbarFrame=theView.frame; if ([isHidden boolValue]) { tabbarFrame=CGRectMake(tabbarFrame.origin.x, tabBarController.view.frame.size.height, tabbarFrame.size.width, tabbarFrame.size.height); } else { tabbarFrame=CGRectMake(tabbarFrame.origin.x, tabBarController.view.frame.size.height - tabbarFrame.size.height, tabbarFrame.size.width, tabbarFrame.size.height); } theView.frame=tabbarFrame; break; } } for(UIView *theView in tabBarController.view.subviews) { if(![theView isKindOfClass:[UITabBar class]]) { CGRect theViewFrame=theView.frame; if ([isHidden boolValue]) { theViewFrame=CGRectMake(theViewFrame.origin.x, theViewFrame.origin.y, theViewFrame.size.width, theViewFrame.size.height + tabbarFrame.size.height); } else { theViewFrame=CGRectMake(theViewFrame.origin.x, theViewFrame.origin.y, theViewFrame.size.width, theViewFrame.size.height - tabbarFrame.size.height); } theView.frame=theViewFrame; } } [UIView commitAnimations]; } 

I used the following code to call hidetabbar: method

 //In my UISplitViewController custom implementation - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { @synchronized(self){ //change the self.splitDetailController to your UITabBarController object [self.splitDetailController performSelector:@selector(hidetabbar:) withObject:[NSNumber numberWithBool:UIInterfaceOrientationIsLandscape(interfaceOrientation)] afterDelay:0.5]; } return YES; } 

I tested this code to work only in the simulator, let me know if it works on the device; -)

+3
Dec 21 '11 at 3:18
source share

Do you have the autoResizingMask parameter set in the subtitle?

 view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 

Something like this should do the trick and allow the view sitting on top of the stack to resize.

0
Dec 30 '09 at 20:10
source share

The obvious solution supporting your original architecture would be to present this view in different ways:

 - (void)tabBarController:(UITabBarController *)tb didSelectViewController:(UIViewController *)vc { if (tb.selectedIndex == MODALONE) { UIViewController* mod = [[UIViewController alloc] initWithNibName: @"ModalView" bundle: nil]; [tb presentModalViewController:mod animated:NO]; [mod release]; } } 

Now the view covers the entire screen (except for the status bar there is one), including the tab bar, so it looks like the tab bar has gone in response to the user clicking this tab bar item.

0
Nov 01 '10 at 19:46
source share

autoresist mask is numbered. Try to set all the parameters and check if the autoresize subviews option is enabled in the parent view

0
May 04 '13 at 12:27
source share

You can create a tab category and show / hide easily. and you can access the full view.

create category #import "UITabBarController+HideTabBar.h"

 @implementation UITabBarController (HideTabBar) - (void)hideTabBarAnimated:(BOOL)animated { CGRect statusbarFrame = [UIApplication sharedApplication].statusBarFrame; CGRect tabBarControllerFrame = self.view.frame; if (statusbarFrame.size.height>20) { tabBarControllerFrame.size.height = screenSize.size.height + self.tabBar.frame.size.height - 20.0; } else { tabBarControllerFrame.size.height = screenSize.size.height + self.tabBar.frame.size.height ; } if (animated) { [UIView animateWithDuration:0.2 animations:^{ [self.view setFrame:tabBarControllerFrame]; } completion:^(BOOL finished) { }]; } else [self.view setFrame:tabBarControllerFrame]; } - (void)showTabBarAnimated:(BOOL)animated { CGRect statusbarFrame = [UIApplication sharedApplication].statusBarFrame; CGRect tabBarControllerFrame = self.view.frame; if (statusbarFrame.size.height>20) { tabBarControllerFrame.size.height = screenSize.size.height - 20.0; } else { tabBarControllerFrame.size.height = screenSize.size.height ; } if (animated) { [UIView animateWithDuration:0.2 animations:^{ [self.view setFrame:tabBarControllerFrame]; } completion:^(BOOL finished) { }]; } else [self.view setFrame:tabBarControllerFrame]; } @end 

Note : the use of statusbarFrame used when a hotspot or call is enabled, so the tab will not be reduced.

Now import the category in which you want to use the methods, and simply call the methods below to hide or show the tab.

 [self.tabBarController hideTabBarAnimated:YES]; [self.tabBarController showTabBarAnimated:YES]; 

Hope this helps.

0
Apr 14 '15 at 5:01
source share

Hope this works.

 @interface UITabBarController (Additions)

 - (void) setTabBarHidden: (BOOL) hidden animated: (BOOL) animated;

 @end

 @implementation UITabBarController (Additions)

 - (void) setTabBarHidden: (BOOL) hidden animated: (BOOL) animated
 {
     if (animated)
     {
         [UIView beginAnimations: nil context: nil];
     }
     if (hidden)
     {

         self.tabBar.frame = CGRectMake (self.tabBar.frame.origin.x, self.tabBar.superview.frame.size.height, self.tabBar.bounds.size.width, self.tabBar.bounds.size.height) ;
     }
     else
     {
         self.tabBar.frame = CGRectMake (self.tabBar.frame.origin.x, self.tabBar.superview.frame.size.height - self.tabBar.frame.size.height + 10, self.tabBar.bounds.size. width, self.tabBar.bounds.size.height);
     }
     if (animated)
     {
         [UIView commitAnimations];
     }

 }

0
Jun 29 '15 at 14:42
source share

Here is my solution (my table view controller is inside the navigation controller for good measure) ... So, I subclassed the UITabBarController and did this ... exposing the -setTabBarHidden: method -setTabBarHidden:

 - (void)setTabBarHidden:(BOOL)hidden { _tabBarHidden = hidden; [UIView performWithoutAnimation:^{ [self adjustViews]; }]; } - (void)adjustViews { if ( _tabBarHidden ) { CGRect f = self.tabBar.frame; // move tab bar offscreen f.origin.y = CGRectGetMaxY(self.view.frame); self.tabBar.frame = f; // adjust current view frame self.selectedViewController.view.frame = self.view.frame; } else { CGRect f = self.tabBar.frame; // move tab bar on screen f.origin.y = CGRectGetMaxY(self.view.frame) - (CGRectGetMaxY(self.tabBar.bounds) + CGRectGetMaxY(self.navigationController.navigationBar.frame)); self.tabBar.frame = f; // adjust current view frame f = self.view.bounds; f.size.height -= CGRectGetMaxY(self.tabBar.bounds); self.selectedViewController.view.frame = f; } } - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; [UIView performWithoutAnimation:^{ [self adjustViews]; }]; } - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; [UIView performWithoutAnimation:^{ [self adjustViews]; }]; } 
0
Aug 27 '16 at 9:33
source share

put the statement in the init method of the UIViewController

 override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) self.hidesBottomBarWhenPushed = true setupDependencyConfigurator() } 
0
Oct 03 '17 at 13:09 on
source share

See this topic:

Show / hide TabBarController in iphone

In short, you can see an example of this behavior in this code example:

http://developer.apple.com/iphone/library/samplecode/TheElements/index.html

-one
Jan 08 '10 at 6:26
source share

Why do not you use the navigation controller. It’s much easier to hide the navigation bar than the tab bar ...

-3
Dec 30 '09 at 23:34
source share

Just made the following code in Monotouch inside a subclass of UITabBarController:

  public void ShowTabBar() { UIView.BeginAnimations("Anim"); UIView.SetAnimationDuration(0.25f); this.View.Subviews[0].Frame = new RectangleF(0f, 0f, 320f, 431f); this.TabBar.Frame = new RectangleF(0f, 431f, 320f, 49f); this.TabBar.Hidden = false; UIView.CommitAnimations(); } public void HideTabBar() { UIView.BeginAnimations("Anim"); UIView.SetAnimationDuration(0.25f); this.View.Subviews[0].Frame = new RectangleF(0f, 0f, 320f, 480f); this.TabBar.Frame = new RectangleF(0f, 481f, 320f, 510f); this.TabBar.Hidden = true; UIView.CommitAnimations(); } 
-3
Feb 08 '12 at 23:40
source share



All Articles