jchmilew
jchmilew

Reputation: 318

How to keep the tab bar hidden while switching between more than 5 tabs

I have a UITabBarController as my root view controller for my app. It has 6 tabs but the app has a custom popup view with 6 buttons used to selected each of the tabs. The tab bar itself is hidden at all times.

The problem is once I try to programmatically select a tab at index 5 or 6 I get an issue. Tabs 1-4 are fine, they get selected in code and the new view controller appears on screen. But since tabs 5 & 6 are technically in the "more" tab, the tab bar appears briefly, shows animation to select the "more" tab and then disappears again. This also puts these "extra" view controllers in a new navigation controller with the "more" table view as the root view controller. This adds a new navigation bar and causes other issues.

Is there any way to do any of the following?

  1. Have more than 5 tabs in a tab bar without the "more" tab.
  2. Disable the "more" tab bar selection animation and the addition of the associated navigation controller.
  3. Create a simple custom controller that could replace the UITabBarController entirely.

It seems like there are a lot of situations where one would want to show more than 5 tabs and yet hide the tab bar but I couldn't find anyone discussing this issue.

Upvotes: 1

Views: 1184

Answers (2)

Abhishek Nath
Abhishek Nath

Reputation: 82

Try the code below . The ViewController used here is a sub class of UITabBarController. In the .h file add ITabBarDelegate , UITabBarControllerDelegate.I guess this way you can add 6 tabs. I have done two tabs here and transition with animation. Use the delegate method

  • (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController

as shown below to apply animations.

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    fvcontroller = [self.storyboard instantiateViewControllerWithIdentifier:@"navcontroller"];
    svcontroller = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
    NSMutableArray *viewcontrollers = [[NSMutableArray alloc]init];
    [viewcontrollers addObject:fvcontroller];
    [viewcontrollers addObject:svcontroller];


    [self setViewControllers:viewcontrollers];

    fvcontroller.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"Me" image:[UIImage imageNamed:@"me.png"] tag:1];
    svcontroller.tabBarItem =  [[UITabBarItem alloc]initWithTitle:@"Chat" image:[UIImage imageNamed:@"chat3.png"] tag:2];
    // _tbbar.delegate = self;
    self.delegate = self;

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}


- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    UIView *from = self.selectedViewController.view;
    UIView *to = viewController.view;
    NSInteger fromindex = [self.viewControllers indexOfObject:self.selectedViewController];
    NSInteger toindex = [self.viewControllers indexOfObject:viewController];

    [UIView transitionFromView:from
                        toView:to
                      duration:.5
                       options:UIViewAnimationOptionTransitionFlipFromBottom
                    completion:^(BOOL finished) {
                        if (finished) {
                            tabBarController.selectedIndex = toindex;
                        }
                    }];

 //(toindex > fromindex ? UIViewAnimationOptionTransitionCurlUp : UIViewAnimationOptionTransitionCurlDown)

    return NO;
}
@end

Upvotes: 0

Joe
Joe

Reputation: 76

According to your requirements, I think you need a custom tabar controller.

This project may help you:

RDVTabBarController

Besides, I must warn you that using custom tabbar controller you may lost the chances to use the convenient features that system tabber contrller provides.

You should use the custom tabbar controller only if the system tabbar controler doesn't fit you needs.

Upvotes: 0

Related Questions