Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any Tab Bar events for notifying when someone hides/shows the Tab Bar?

I have a Nav controller inside a custom subclass of Tab Bar controller that i created.

I want to know from within the (custom) Tab Bar whenever one of the displayed controllers attempts to hide or show the Tab Bar. (for example when pushing a VC that has its hidesBottomBarWhenPushed=YES onto the Nac controller).

In short i want to be notified of events hiding/showing the Tab Bar but could not find anything in Apple's reference. I tried looking at UITabBar, UITabBarDelegate, UITabBarController, and UITabBarControllerDelegate but all seem to only provide functionality related to the tab bar items.

Thanks in advance.

like image 786
nsof Avatar asked Dec 30 '10 14:12

nsof


People also ask

How do you hide the tab bar when a view controller is shown?

If you don't want that behavior, you should set hidesBottomBarWhenPushed to true where applicable. This will hide the tab bar along with any toolbars you had showing, but only when a view controller is pushed onto the navigation stack. This allows you to show the tab bar at first, then hide it when you need more room.

How do I hide the tab bar in IOS?

Simply, Go to ViewController (in StoryBoard) -> Attribute inspector -> Under 'View Controller' section select 'Hide Bottom Bar on Push' checkbox. This works like a charm.

How do I hide the bottom bar in Swift?

Answer: Use self. tabBarController?. tabBar. hidden instead of hidesBottomBarWhenPushed in each view controller to manage whether the view controller should show a tab bar or not.


1 Answers

If you are using a tab bar controller, UIKit explicitly states that every navigation controller instance that will be displayed in the tab bar controller's context will be among its viewControllers property. Now every UINavigationController instance has a delegate, which defines a navigationController:willShowViewController:animated: method which lets you know when a view controller is pushed onto it.

By setting your tab bar controller as the delegate of every navigation controller that is pushed onto it, you can analyze wether the view controller being pushed has the hidesBottomBarWhenPushed property set and generate an event when this is the case.

The algorithm used to hide the tab bar controller's tab bar is as follows: when a view controller is pushed on a navigation controller which is itself contained in a tab bar controller, if any view controller in the navigation stack of the navigation controller has the hidesBottomBarWhenPushed property set, then the tab bar should be hidden.

So the tab bar is hidden when a navigation controller is selected and one of the view controllers in its stack have the hidesBottomBarWhenPushed property set.

like image 197
ndfred Avatar answered Oct 18 '22 17:10

ndfred