没有UITabBar的UITabBarController

我试图从UITabBarController中隐藏/删除UITabBar。 我的iPhone版本中有一个UITabBar,但是我已经将导航移到了iPad版本的新视图控制器中。 新菜单使用UITabBarDelegate方法在UIViewControllers之间切换。

到现在为止还挺好。

我现在需要的是以某种方式隐藏UITabBar。

我有一个自定义的UITabBarController,我试着简单地使用self.tabBar.hidden = YES; 但我需要视图来填充屏幕。

谢谢

所以你有几个select。 假设你的标签视图是导航控制器。 在这种情况下,你可以有一个临时的viewController,立即推动你想使用的“真正的”viewController,而“真正的”有一个下面的方法实现。 稍后,通过重置navigationControllers viewControllers数组,您可以摆脱临时控制器的好处。

- (BOOL) hidesBottomBarWhenPushed { return YES; } 

如果这不适合你,那么你可以用window.rootViewController玩游戏。 在启动时,您创build您的viewController并使其成为rootViewController。 后来,当你想要一个标签栏,你可以消息回到appDelegate创build一个tabBarController,并使您的视图第一个viewController(就像!)。 我只是使用Xcode Tab Bar项目在一个简单的演示应用程序中validation了这一点。 这是我使用的代码:

 - (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; } 

我find了我正在寻找的答案

希望这对别人有帮助

 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)]; } }