Im trying to hide the tab bar for a specific view and show it back when the screen is touch. I want it to have the similar effect as youtube, for example when the video is playing the player controls is hidden and the screen is touched the controls are shown again.
How to hide iOS tab bar for a particular tab index and tab is shown back when the screen is touched?
-
See my answer to a similar question here: http://stackoverflow.com/a/9141766/91458 Best, – boliva Feb 04 '12 at 15:03
4 Answers
You can use this code to show and hide the tab bar:
@implementation UITabBarController (Extras)
-(void)showTabBar:(BOOL)show {
UITabBar* tabBar = self.tabBar;
if (show != tabBar.hidden)
return;
UIView* subview = [self.view.subviews objectAtIndex:0];
CGRect frame = subview.frame;
frame.size.height += tabBar.frame.size.height * (show ? -1 : 1);
subview.frame = frame;
tabBar.hidden = !show;
}
This code works, was recently accepted by Apple in an app, and (as a category) I found easier to use than other solutions.
When you want to hide the tabBar, just call:
[self.tabBarController showTabBar:NO];
Likewise, to show it again, call this message with YES
as the parameter.
NOTE: Somehow I had forgotten that I had already looked up this code at some point in the past, and I'm now unsure of who answered it originally. Saurabh answered a similar question.
The code provided by Saurabh iterates over all views looking for isKindOfClass:[UITabBar class]
, whereas I just grab the first subview -- which might be fragile in the face of updates.
Have you tried just straight up hiding the tab bar?
In the View Controller you want to not have a tab bar, add tabBar.hidden = YES;
to viewWillAppear:
or viewDidAppear:
to reverse that have a touch-up-inside event trigger tabBar.hidden = NO;
I've not done this with tab bars personally, but this works with other views, so it's the way I would try first.

- 11,919
- 7
- 56
- 78
-
Does indeed hide the tab bar, but I'm getting a 49-pixel tall white space at the bottom of the screen now. The view does not auto-resize to fill it, and trying to manually change the view frame does nothing. – AndrewS Sep 30 '11 at 16:43
-
1@AndrewS check out this question http://stackoverflow.com/questions/3807255/how-do-i-hid-the-uitabbarview-when-loading-some-view – Kenny Winker Sep 30 '11 at 23:34
-
That's for a pushed view; I wanted it for one tab in a tab bar. I wound up using the code in [How to hide uitabbarcontroller](http://stackoverflow.com/questions/5272290) – AndrewS Oct 01 '11 at 18:56
-
Try This Code
- (void) hideTabBar:(UITabBarController *) tabbarcontroller
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
float fHeight = screenRect.size.height;
if( UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
{
fHeight = screenRect.size.width;
}
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];
view.backgroundColor = [UIColor blackColor];
}
}
[UIView commitAnimations];
}
- (void) showTabBar:(UITabBarController *) tabbarcontroller
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
float fHeight = screenRect.size.height - 49.0;
if( UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
{
fHeight = screenRect.size.width - 49.0;
}
[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, fHeight, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];
}
}
[UIView commitAnimations];
}

- 626
- 7
- 19
Try this:
self.tabBarController.tabbar.hidden = YES;
Put it in viewDidLoad.

- 19,393
- 7
- 65
- 62