Hiding UITabBar when pushing a UIView

2019-01-07 07:04发布

I have a UITabBarController where the default view controller is a UINavigationController. I want to be able to hide the UITabBar of the UITabBarController when I push a certain view in the UINavigationController.

I've tried adding:

delegate.tabBarController.hidesBottomBarWhenPushed = YES;

in my UINavigationController before I push the view, but that doesn't seem to do the trick.

Any tips on what I should be doing or if it's even possible? Thanks in advance!

8条回答
叼着烟拽天下
2楼-- · 2019-01-07 08:05

Here's how you get this to work:

In the Application Delegate you create the UITabBarController. Then you create a UINavigationController with its root controller as the view controller you want in the particular tab. Then insert the UINavigationController into the "viewControllers" array of the UITabBarController. like so:

ViewControllerForTab1 *tab1Controller = [[ViewControllerForTab1 alloc] initWithNibName:@"ViewControllerForTab1"];

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:tab1Controller];

[tab1Controller release];


UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects: navController, nil];

[navController release];


[self.window addSubView:tabBarController.view];

This way you can set the "hidesBottomBarWhenPushed" property to "YES" in any view controller inside that UINavigationController and it will hide the UITabBar.

Hope that helps!

查看更多
劳资没心,怎么记你
3楼-- · 2019-01-07 08:06

It turns out that if you set the view hidesBottomBarWhenPushed:YES it hides the bar when the view appears (duh on my part). I was assigning it to the UITabBarController, which doesn't make too much sense when you think about it.

[self.view hidesBottomBarWhenPushed:YES];
[super pushViewController:viewController animated:animated];
查看更多
登录 后发表回答