I have a navigation controller. For one of the views i want to hide the bottom tab bar, so it gets the max possible screen real estate. To do this, i have:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.hidesBottomBarWhenPushed = YES; // To hide the tab bar
}
return self;
}
But for the next view that i push on the stack, i want the tab bar to reappear. Is there a way to do this?
One can make it reappear but it will result in an incorrect animation. Page comes in left and the bottom bar right. So it is probably not the behavior you want. But in the same controller, do
self.hidesBottomBarWhenPushed = NO;
before pushing the next view controller in.I'm have solved this problem like that:
Almost all my ViewControllers are children of BaseViewController.
So, example:
Just override variable "prefersBottomBarHidden" in ViewController where BottomBar should be hidden:
In a root view controller "A" (which is showing the tabBar), when it comes time to show another view controller "B" where no tabBar is wanted:
In view controller B, when it comes time to show a third view controller C (tabBar wanted again):
Case one: To hide UITabbarController in a cetain UIVIewController, for example while calling
self.performSegueWithIdentifier("Identifier", sender: self)
, it is necesssary prior to to that, setself.hidesBottomBarWhenPushed = true
flag. And afterself.hidesBottomBarWhenPushed = false
flag. But we have to understad that through one UIViewController, UITabbarController will re-appear and, in case if you need to use UITabbarController with single UIViewControler, it wont yield right result.Case Two: To hide UITabbarController in a certain UIVIewController, after which a UITabbarController should be popped, it is necessary, for example, while calling
self.performSegueWithIdentifier("nextController", sender: self)
, to setself.hidesBottomBarWhenPushed = true
before the method. AlsewillMoveToParentViewController(parent: UIViewController?)
in the method should be configured as it shown in the code example.Swift 3 code:
It's been a while since this question was asked, but none of these answers address using Storyboard segues. It turns out to be pretty easy:
As of iOS5, there's a very easy means of accomplishing this. It's essentially the same method as Deepak, but there aren't any artifacts with the animation - everything looks as expected.
On init, set
just as you have above. When it's time to push the new controller on the stack, it's as simple as:
It's important to reset the value to YES after the controller has been pushed in order to re-hide the bar when the user taps the Back button and the view comes back into view.