Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide TabBar and show NavigationController toolbar on button click

I have the following view hierarchy:

Tab Bar Controller -> Navigation Controller -> Custom View Controller

In my Custom View I want the TabBar to disappear and show a toolbar instead. Much like in iOS7 native photos app when pressing 'select'.

I tried different solutions I found of SO but managed to get either:

  1. TabBar hidden and Toolbar shown with black gap
  2. TabBar hidden and Toolbar hidden
  3. TabBar hidden Toolbar shown with gap from bottom. However, Custom view content reaches the bottom of the screen (under the toolbar and in the same place the tab bar used to be)

The difference from other solutions I found is that I need this to happen on click and not on push.

Some of the things I tried:

// #1
[self.navigationController.toolbar setHidden:!isSelecting];
[self.tabBarController.tabBar setHidden:isSelecting];

// #2
self.hidesBottomBarWhenPushed = YES;

// #3
#1 & #2 variants @ different controller along the path
like image 807
Xyand Avatar asked Jun 22 '14 16:06

Xyand


1 Answers

Eventually, after playing with the settings I managed to make it work. I'm not sure why it works now and didn't work before so I'd appreciate your comments.

Storyboard:

  1. Mark as checked "Hide Bottom Bar on Push" for the Custom View Controller
  2. Mark as checked "Show Toolbar" for the Navigation Controller

Code:

On button click hide/unhide tabBar: [self.tabBarController.tabBar setHidden:state]

This almost works. It does hide/unhide the tabBar when pressing the button but the only problem is that the tabBar is initially hidden when switching tabs. I had to do some extra effort to have it visible.

Set UITabBarControllerDelegate to unhide tabBar when switching tabs. I did it in a custom SUSourceTabController:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.delegate = self;
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:   (UIViewController *)viewController
{
    [self.tabBar setHidden:NO];
}

We also need to unhide it for the first tab view in the Custom View Controller code. Using setHidden:NO in any other place in the code didn't work.

- (void)viewDidLoad
{
    [super viewDidLoad];    
    [self.tabBarController.tabBar setHidden:NO];
}
like image 108
Xyand Avatar answered Oct 20 '22 16:10

Xyand