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:
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
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:
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];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With