Hide TabBar and show NavigationController navigation bar when button is clicked

I have the following view hierarchy:

Tab bar controller β†’ Navigation controller β†’ User view controller

In my user view, I want the TabBar to disappear and display the toolbar. As in the application for native photos iOS7 when you press "select".

I tried different solutions that I found from SO, but I managed to get:

  • The TabBar is hidden and the toolbar is shown with a black gap.
  • hidden tabbar and hidden toolbar
  • the hidden TabBar toolbar is shown with a gap below. However, the contents of the user view reaches the bottom of the screen (under the toolbar and in the same place where the tab bar was)

The difference from the other solutions that I found is that I need this to happen when clicked, not clicked.

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 
+6
source share
2 answers

In the end, after playing with the settings, I managed to get it to work. I'm not sure why it works now and has not worked before, so I will be grateful for your comments.

Storyboard:

  • Check as β€œHide bottom panel on click” for the custom view controller.
  • Mark as marked "Show toolbar" for the navigation controller

Code:

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

It almost works. It hides / displays the tabBar when the button is clicked, but the only problem is that the tabBar is initially hidden when switching tabs. I had to make extra efforts to make it visible.

Set UITabBarControllerDelegate to display tabBar when switching tabs. I did this in a regular SUSourceTabController :

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

We also need to display it for the first tab type in the code of the custom controller view. Using setHidden:NO anywhere else in the code did not help.

 - (void)viewDidLoad { [super viewDidLoad]; [self.tabBarController.tabBar setHidden:NO]; } 
+6
source

Drop this question category.

UITabBarController + HideTabbar.h

 #import <UIKit/UIKit.h> @interface UITabBarController (HideTabbar) - (void)setHidden:(BOOL)hidden animated:(BOOL)animated; @end 

UITabBarController + HideTabbar.m

 #import "UITabBarController+HideTabbar.h" #define kAnimationDuration .3 @implementation UITabBarController (HideTabbar) - (void)setHidden:(BOOL)hidden animated:(BOOL)animated { CGRect screenRect = [[UIScreen mainScreen] bounds]; float fHeight = screenRect.size.height; if (UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) { fHeight = screenRect.size.width; } if (!hidden) { fHeight -= self.tabBar.frame.size.height; } CGFloat animationDuration = animated ? kAnimationDuration : 0.f; [UIView animateWithDuration:animationDuration animations:^{ for (UIView *view in self.view.subviews){ if ([view isKindOfClass:[UITabBar class]]) { [view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)]; } else { if (hidden) { [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)]; } } } } completion:^(BOOL finished){ if (!hidden){ [UIView animateWithDuration:animationDuration animations:^{ for(UIView *view in self.view.subviews) { if (![view isKindOfClass:[UITabBar class]]) { [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)]; } } }]; } }]; } @end 
0
source

Source: https://habr.com/ru/post/971180/


All Articles