Hide/Show Tab Bar When Push/Back. Swift

hide / show tab bar when push / back. swift

As it's name suggest, hiddenBottomBarWhenPushed only hide bottom bar if needed, it will not unhide bottomBar.
You can do this to get it works:

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.tabBarController?.tabBar.hidden = true/false
}

or simply put self.tabBarController?.tabBar.hidden = true/false in prepareForSegue

But I would not recommend you to do so, as it would be weird if bottomBar suddenly popped out, user will thought they suddenly back to rootViewController while they are not.

Users should always know where they are in your app and how to get to their next destination.

how to hide tab bar when push and show tab bar when back

Edit: That solved the problem.

It makes sense that the tab bar is appearing because when going clicking back from VC2 to VC3, nothing is telling VC3 to hide its Tab Bar.

I think you have 2 solutions here (but haven't tested any):

  1. You can try doing something like this guy did. He added the hidesBottomBarWhenPushed logic in BackButtonPressed Handler.
  2. In VC3, do self.tabBarController?.tabBar.hidden = true in ViewDidLoad or viewWillAppear

How do you hide/unhide the tab bar when pushing/popping

I actually figured it out. Basically in your viewdidAppear you add in self.hidesBottomBarWhenPushed = true and in your viewDidDisappear you add in
self.hidesBottomBarWhenPushed = false. Thanks for your guys's answers anyways.

Hide tab bar in IOS swift app

You can simply use this in your ViewDidLoad() method.

self.tabBarController?.tabBar.hidden = true

For Swift 3.0, 4.0, 5.0:

self.tabBarController?.tabBar.isHidden = true

Or you can change z position of tab bar this way:

self.tabBarController?.tabBar.layer.zPosition = -1

and if you want to show it again then:

self.tabBarController?.tabBar.layer.zPosition = 0

How do you really hide and show a tab bar when tapping on part of your view? (no buttons but any location of the screen)

Have a variable isTabBarHidden in class which stores if the tabBar has been animated to hide. (You could have used tabBar.isHidden, but that would complicate the logic a little bit when animate hiding and showing)

class ViewController {

var isTabBarHidden = false // set the default value as required

override func viewDidLoad() {
super.viewDidLoad()

let tap = UITapGestureRecognizer(target: self, action: #selector(touchHandled))
view.addGestureRecognizer(tap)
}

@objc func touchHandled() {
guard let tabBarControllerFound = tabBarController else {
return
}
tabBarController?.hideTabBarAnimated(hide: !isTabBarHidden)
isTabBarHidden = !isTabBarHidden
}

}

TabBar is hidden after going back to the initial ViewController of a TabBarController Using Segue

When you are using the modal presentation segue, you are creating a completely new instance of HomeViewController. The new HomeViewController is not linked to the TabBarController in your hierarchy.

Here's you initial view hierarchy:

TabBarController
-> HomeVC
-> CreateVC (Navigation Controller)
-> CreateQuizVC
-> SavedVC

Now after tapping the back button you'll get the following:

TabBarController
-> HomeVC
-> CreateVC (Navigation Controller)
-> CreateQuizVC
-> HomeVC(2)
-> SavedVC

What you could do is, instead of using the segue to go back, add an IBAction in your code to set the selectedIndex of the TabBar programatically, and link the Back UIBarButtonItem to this IBAction.

@IBAction func backButtonAction(_ backButton: UIBarButtonItem) {
// Keep in mind that the CreateQuizVC is embeded in a NavigationController.
// The NavigationController is the child of the TabBarController
navigationController?.tabBarController?.selectedIndex = 0
navigationController?.tabBarController?.tabBar.isHidden = false
}

However, my suggestion is you use the TabBar as it's intended by Apple. Don't hide it while you're presenting your CreateQuizVC, and use the TabBar to navigate between the tabs. This will help with user experience, since everybody on iOS is expecting this behaviour from a TabBar.

how to hide tab bar in the view controller that embedded in the navigation stack in swift?

Use in prepareforsegue while pushing and set hidesBottomBarWhenPushed to true to hide the tabbar on destination view controller.

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "InvoiceVC") {
let indexPath: IndexPath? = tableView.indexPathForSelectedRow
let destViewController = segue.destination as? InvoiceVC
destViewController?.recipeName = recipes[indexPath?.row ?? 0]
destViewController?.hidesBottomBarWhenPushed = true
}
}

How to hide the tabBar when push a view?

use this methood in the UIViewController class where you want to hide the tabBarController

-(BOOL)hidesBottomBarWhenPushed
{
return YES;
}

Update

As suggested by @Yuchen Zhong in his answer, This option is now available in the storyboard itself.

Sample Image

How to hide/show tab bar of a view with a navigation bar in iOS?

You can set the UIViewController.hidesBottomBarWhenPushed instead:

DetailViewController *detailViewController = [[DetailViewController alloc] init];
detailViewController.hidesBottomBarWhenPushed = YES;
[[self navigationController] pushViewController:detailViewController animated:YES];
[detailViewController release];

Tab bar not visible on coming back to selected item

Finally figured out the issue. One of my view controller in storyboard had hide tab bar on push view controller enabled causing the tab bar to hide in my expected view controller. On unchecking it and handling all hide/show tab bar in source code itself, i am able to fix the issue.



Related Topics



Leave a reply



Submit