0

I was just wondering how I can hide the tab item in the Tab Bar Controller for the current view controller which is selected

Wez
  • 10,555
  • 5
  • 49
  • 63
Bobby W
  • 836
  • 8
  • 22

3 Answers3

3

Remove intended index from controllersArray ex. (1)

NSMutableArray *controllersArray = [NSMutableArray  arrayWithArray:self.tabBar.viewControllers];
[controllersArray removeObjectAtIndex: 1];
[self.tabBar setViewControllers:controllers animated:YES];

Check for this answer also I found this similar from your question Hide tab bar item and aligning other tab items Hope this helps you.!!

Community
  • 1
  • 1
Jemythehigh
  • 583
  • 5
  • 12
1

Firstly, I don't think it's possible to hide a UITabBarItem - It inherits from UIBarItem but there is no hidden property - UIBarItem Documentation

You could try comparing the tab bars selectedViewController property against your current view controller? - Something like below might work..

if (self.tabBarController.selectedViewController == self) {
    // Do Stuff
}

But even then I think you are going to find it hard to hide the tab bar item itself.

Wez
  • 10,555
  • 5
  • 49
  • 63
  • 1
    Yeah, after reading some more. I figured the best solution for my situation, is to remove it completely, once done with that view controller. i.e. the login screen. – Bobby W Apr 14 '15 at 13:13
0
UIView *parent = self.tabBarController.tabBar.superview; // UILayoutContainerView
    UIView *content = [parent.subviews objectAtIndex:0];  // UITransitionView
    UIView *window = parent.superview;

    [UIView animateWithDuration:0.2
                     animations:^{
                         CGRect tabFrame = self.tabBarController.tabBar.frame;
                         tabFrame.origin.y = CGRectGetMaxY(window.bounds);
                         self.tabBarController.tabBar.frame = tabFrame;
                         content.frame = window.bounds;
                     }];
Rahul Mayani
  • 3,761
  • 4
  • 25
  • 40