Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding tabBar showing black bar in Ios7

I am using this code to hide the TabBar:

self.tabBarController.tabBar.hidden=YES;

I am hiding tabBarController in my project.but it showing black bar in bottom of the view in Ios7.When i go back to the same view it is looking good.any help will be appreciated.

like image 593
user2681789 Avatar asked Oct 07 '13 12:10

user2681789


People also ask

How do I hide the tab bar in Swift?

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 TabBar when pushing?

You can do this in storyboard now: Select the UIViewController in your storyboard. Select the checkbox Hide Bottom Bar on Push.

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.

What is tab bar in iOS?

A TabBar is a control that is used to display and configure one or more bar button items in a tab bar for selecting between different subtasks, views, or modes in the iOS application. The TabBar is used in association with the TabBarController to present the list of tabs in the application.


3 Answers

NOTE: It is solution for iOS6 and 7 only.

In iOS 7 to extend clickable area and hide black bar on place of hidden UITabBar you should enable 'Extend Edges - Under Opaque Bars' option for you UIViewController.

Extend Edges - Under Opaque Bars option

Or you can set this property programmatically:

[self setExtendedLayoutIncludesOpaqueBars:YES]

Here is example of code that hide or move TabBar for iOS 6/7:

UITabBarController *bar = [self tabBarController]; if ([self respondsToSelector:@selector(setExtendedLayoutIncludesOpaqueBars:)]) {     //iOS 7 - hide by property     NSLog(@"iOS 7");     [self setExtendedLayoutIncludesOpaqueBars:YES];     bar.tabBar.hidden = YES; } else {     //iOS 6 - move TabBar off screen     NSLog(@"iOS 6");     CGRect screenRect = [[UIScreen mainScreen] bounds];     float height = screenRect.size.height;     [self moveTabBarToPosition:height]; }  //Moving the tab bar and its subviews offscreen so that top is at position y -(void)moveTabBarToPosition:(int)y {      self.tabBarController.tabBar.frame = CGRectMake(self.tabBarController.tabBar.frame.origin.x, y, self.tabBarController.tabBar.frame.size.width, self.tabBarController.tabBar.frame.size.height);      for(UIView *view in self.tabBarController.view.subviews) {         if ([view isKindOfClass:[UITabBar class]]) {             [view setFrame:CGRectMake(view.frame.origin.x, y, view.frame.size.width, view.frame.size.height)];         } else {             [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, y)];             view.backgroundColor = [UIColor blackColor];         }     } } 

Function to moving the Tab Bar offscreen got from this post.

like image 186
CTiPKA Avatar answered Sep 20 '22 08:09

CTiPKA


Next code works for me

- (void)showTabBar { [self.tabBar setTranslucent:NO]; [self.tabBar setHidden:NO]; }  - (void)hideTabBar {     [self.tabBar setTranslucent:YES];     [self.tabBar setHidden:YES]; } 
like image 27
PSsam Avatar answered Sep 21 '22 08:09

PSsam


Try this:

- (BOOL)hidesBottomBarWhenPushed {
     return YES;
}
like image 40
Tea Avatar answered Sep 22 '22 08:09

Tea