Iphone: Is it possible to hide the TabBar? (Pre-iOS 8) Iphone: Is it possible to hide the TabBar? (Pre-iOS 8) ios ios

Iphone: Is it possible to hide the TabBar? (Pre-iOS 8)


Here's my code for that:

This is, of course, mucking with the goings on in the controller's view hierarchy. It could change/break. This uses defined APIs, so Apple won't care, but they won't care about breaking your code, either.

- (void)hideTabBar {  UITabBar *tabBar = self.tabBarController.tabBar;  UIView *parent = tabBar.superview; // UILayoutContainerView  UIView *content = [parent.subviews objectAtIndex:0];  // UITransitionView  UIView *window = parent.superview;  [UIView animateWithDuration:0.5                   animations:^{                     CGRect tabFrame = tabBar.frame;                     tabFrame.origin.y = CGRectGetMaxY(window.bounds);                     tabBar.frame = tabFrame;                     content.frame = window.bounds;                   }];  // 1}- (void)showTabBar {  UITabBar *tabBar = self.tabBarController.tabBar;  UIView *parent = tabBar.superview; // UILayoutContainerView  UIView *content = [parent.subviews objectAtIndex:0];  // UITransitionView  UIView *window = parent.superview;  [UIView animateWithDuration:0.5                   animations:^{                     CGRect tabFrame = tabBar.frame;                     tabFrame.origin.y = CGRectGetMaxY(window.bounds) - CGRectGetHeight(tabBar.frame);                     tabBar.frame = tabFrame;                     CGRect contentFrame = content.frame;                     contentFrame.size.height -= tabFrame.size.height;                   }];  // 2}

Edit: An anonymous user has suggested the following addition for 7.0 (i have not tested this, and could not say whether it is a workaround or an ideal implementation):

// 1. To Hide the black line in IOS7 only, this extra bit is requiredif (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {    [self.tabBarController.tabBar setTranslucent:YES];}  // 2. For IOS 7 onlyif (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {    [self.tabBarController.tabBar setTranslucent:NO];}

Edit: Entirely untested in 8.x and likely lacking in some layouts.


Like Steve, I haven't found a clean way to do this (even though Apple Photopicker does something similar). Here is what I have done:

 if (systemAction)  {    // Reveal tab bar back    CGRect bounds = [[UIScreen mainScreen] bounds];    CGRect tabBarFrame = self.tabBarController.tabBar.frame;    self.tabBarController.view.frame = CGRectMake(0,0,bounds.size.width,bounds.size.height);    self.toolBar.hidden = YES;    systemAction = NO;  }  else  {    //hide tab bar    CGRect bounds = [[UIScreen mainScreen] bounds];    CGRect tabBarFrame = self.tabBarController.tabBar.frame;    CGRect navigationBarFrame = self.navigationController.navigationBar.frame;    self.tabBarController.view.frame = CGRectMake(0,0,bounds.size.width,bounds.size.height+tabBarFrame.size.height);    self.toolBar.hidden = NO;    CGRect frame = self.toolBar.frame;    frame.origin.y = bounds.size.height - frame.size.height - navigationBarFrame.size.height;    self.toolBar.frame = frame;    systemAction = YES;  }

What it is doing is pushing the view down so I can display a toolbar (and not hiding it). Obviously this is for only the 'root view' of a tabbar + navigation controller. For any subsequent views you can set the 'hidesBottomBarWhenPushed' on the viewcontroller you are pushing.


I tried a number of the solutions above, but no joy in iOS 8. I find that setting in viewWillAppear the following works for me. Should work in iOS 7 as the extendedLayoutIncludesOpaqueBars was introduced then.

    self.extendedLayoutIncludesOpaqueBars = true    self.tabBarController?.tabBar.isHidden = true    self.tabBarController?.tabBar.isOpaque = true

and if you need to turn tabBars on again when you leave to use the following in viewWillDisappear.

    self.tabBarController?.tabBar.isHidden = false    self.tabBarController?.tabBar.isOpaque = false

I use this to allow a return from a transition to keep the TabBar hidden. Not used it in a button action but if like me you find nothing above now works, this could be the basis of a programmable solution.


matomo