How to Hide Tab Bar Controller?
Asked Answered
S

10

24

How to Hide Tab Bar Controller ? I want to hide the Tab Bar controller with double tap on UIImageView.

Siderolite answered 19/9, 2011 at 5:34 Comment(1)
P
38

Try this code:

[self.tabBarController.tabBar setHidden:YES];

where tabbarcontroller is needed to be defined...

EDIT

AppDelegateFileName *appDelegate = (AppDelegateFileName *) [[UIApplication sharedApplication] delegate];
[appDelegate.tabbarController.tabBar setHidden:YES];

before doing this make sure that you create a @property declaration of tabbarController in appDelegate .h file.

Proceleusmatic answered 19/9, 2011 at 5:42 Comment(3)
how can i define tabbarcontroller?Siderolite
UITabbarController *tabbarController; in .h file and just give IBOUTLET in .xib file...Proceleusmatic
i declare tabbar controller in app delegate .... how can i use in myviewcontroller.Siderolite
C
13

If using Storyboards you can simply uncheck a checkbox in your ViewController's Attribute Inspector. It's called "Hide Bottom Bar on Push". Very convenient indeed, and no need to handle the showing of the tabBar again after navigating back from your tabBar-less viewController. I don't know in which XCode-version this was introduced, but it's there for XCode 6 + .

Corroboree answered 15/4, 2015 at 11:4 Comment(0)
L
6

Use Tap Gesture Recognizer to detect double taps on a UIImageView. Then invoke a method on detecting the double double tap. Add the following line of code in that method.

self.tabBarController.tabBar.hidden=YES;

Hope this helps.

Lathrop answered 19/9, 2011 at 5:43 Comment(4)
how to call tabbar controller in this view?Siderolite
what do u mean by call tabbar controller in this view ? Could u pls explain more on that ?Lathrop
hiding tabbar is ok, but tab bar space appear blackZea
@GajendraKChauhan add this line after setting it to hidden: self.edgesForExtendedLayout = UIRectEdgeAll;Mucoprotein
B
4

Use the code below to hide/show tab bar controller in animated style.
hiddenTabBar is a BOOL variable.

- (void) hidetabbar {

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.0];

    for(UIView *view in objtabbar.view.subviews)
    {

        if([view isKindOfClass:[UITabBar class]])
        {

            if (hiddenTabBar) {
                [view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
            } else {
                [view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
            }
        } else {
            if (hiddenTabBar) {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
            } else {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
            }

        }
    }

    [UIView commitAnimations];

    hiddenTabBar = !hiddenTabBar;
}
Bevus answered 19/9, 2011 at 5:58 Comment(0)
C
2

UIViewController has a property

@property(nonatomic, readonly, retain) UITabBarController *tabBarController

which you can set:

self.tabBarController.tabBar.hidden = YES;
Chun answered 25/9, 2012 at 10:4 Comment(0)
D
1

Swift 2.1:

self.tabBarController!.tabBar.hidden = true
Distribute answered 7/3, 2016 at 21:40 Comment(1)
Type safety: self.tabBarController?.tabBar.hidden = trueValorous
N
0

Try this when you push the view to the new view:

self.tabbarconroller.tabbar.hidden = YES;
Nuts answered 19/9, 2011 at 5:58 Comment(0)
K
0

Objective-C

[self.tabBarController.tabBar setHidden:YES];

Swift 3

self.tabBarController?.tabBar.isHidden = true

Swift 2

self.tabBarController?.tabBar.hidden = true
Kauffman answered 22/1, 2018 at 14:44 Comment(0)
S
0

Objective-C

[self.tabBarController.tabBar setHidden:YES];

Objective-C 2.0

self.tabBarController.tabBar.hidden = YES;

Swift before iOS 9

tabBarController?.tabBar.hidden = true

Swift iOS 9 and above

tabBarController?.tabBar.isHidden = true

Extra trick with Swift 5 and above: if you would like to change the hidden property then toggle it

if let t = tabBarController?.tabBar {
    t.isHidden = t.!isHidden
}
// is equal to 
tabBarController?.tabBar.isHidden.toggle()
Slack answered 14/9, 2019 at 14:2 Comment(0)
C
0

Swift Solution for multiple root view controllers

If you or someone would need to hide the tab bar inside a custom controller, for an app that uses multiple rootViewController try something like this:

//instantiate appDelegate in your controller first
let appDelegate = UIApplication.shared.delegate as! AppDelegate

//then just hide the tab bar as following
appDelegate.window?.rootViewController?.tabBarController?.tabBar.isHidden = true
Cub answered 1/8, 2020 at 15:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.