UITabBarController Without a UITabBar

2019-08-07 03:09发布

I'v been trying to hide/remove the UITabBar from a UITabBarController. I've got a UITabBar in my iPhone version but I've moved the navigation to a new view controller for the iPad version. The new menu works using the UITabBarDelegate methods to switch between the UIViewControllers.

So far so good.

All I need now is to somehow hide the UITabBar.

I've got a custom UITabBarController and I've tried simply using self.tabBar.hidden = YES; but i need the view to fill the screen.

Thank you

2条回答
Animai°情兽
2楼-- · 2019-08-07 03:41

Ive Found the answer I was looking for

Hope this is helpful to someone else

for(UIView *view in self.view.subviews)
    {
        if([view isKindOfClass:[UITabBar class]])
        {
            [view setFrame:CGRectMake(view.frame.origin.x, self.view.frame.size.height+49, view.frame.size.width, view.frame.size.height)];
        } 
        else 
        {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, self.view.frame.size.height)];
        }

    }
查看更多
戒情不戒烟
3楼-- · 2019-08-07 03:49

So you have a few options. Suppose that your tab views are navigation controllers. In that case you can have a temporary viewController that immediately pushes the "real" viewController you want to use, and the "real" one has the method below implemented. Later, by resetting the navigationControllers viewControllers array, you can get rid of the temporary controller for good.

- (BOOL) hidesBottomBarWhenPushed { return YES; }

If that does not work for you, then you can play games with the window.rootViewController. At launch, you create your viewController and make it the rootViewController. Later, when you want a tab bar, you can message back to the appDelegate to create a tabBarController and make your view the first viewController (as is!). I just verified this in a simple demo app using the Xcode Tab Bar project. Here is the code I used:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];

    self.window.rootViewController = viewController1;
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)switcher
{
    [viewController1.view removeFromSuperview];
    UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
    self.window.rootViewController = self.tabBarController;
}
查看更多
登录 后发表回答