推UIView时隐藏UITabBar

我有一个UITabBarController默认视图控制器是一个UINavigationController 。 我希望能够隐藏UITabBarController的UITabBar时,我推UINavigationController的某个视图。

我试过添加:

 delegate.tabBarController.hidesBottomBarWhenPushed = YES; 

在我的UINavigationController之前,我推视图,但似乎并没有这样做。

关于我应该做什么或者甚至可能的提示? 提前致谢!

这个更好:

 viewController.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:viewController animated:YES]; 

你必须在控制器上设置hidesBottomBarWhenPushed = YES,以便将其推入视图中…

我已经弄清楚了如何解决这个问题,但是我遇到了同样的问题,但是苹果公​​司也告诉我们如何在名为“The Elements”的示例中这样做( http://developer.apple.com/library/ ios /#samplecode / TheElements / Introduction / Intro.html )

请参阅下面的函数, 添加到要推入的视图的init函数中!

 -(id) init { if(self = [super init]) { self.hidesBottomBarWhenPushed = YES; } return self; } 

它会自动隐藏像照片应用程序在你的iPhone上做的标签栏。 而当你回到父视图将只是再次显示tabbar。

祝你好运

我已经尝试了大部分build议的解决scheme。 最后他们都没有为我工作。

hideTabBarWhenPushed不仅为下一个推送的视图控制器隐藏标签栏,而且还为所有在其中推送的视图控制器隐藏标签栏。 对于那些我希望标签栏控制器重新出现。

Orafaelreis的解决scheme(见上文)似乎是最适合的。 但是他的尝试只能用于严格的肖像取向,甚至没有倒过来。 所以我不得不修补它。 这是我终于得到的:

 #define kTabBarHeight 49 // This may be different on retina screens. Frankly, I have not yet tried. - (void) hideTabBar:(BOOL)hide { // fetch the app delegate AppDelegate *delegate = [[UIApplication sharedApplication] delegate]; // get the device coordinates CGRect bounds = [UIScreen mainScreen].bounds; float width; float height; // Apparently the tab bar controller's view works with device coordinates // and not with normal view/sub view coordinates // Therefore the following statement works for all orientations. width = bounds.size.width; height = bounds.size.height; if (hide) { // The tab bar should be hidden too. // Otherwise it may flickr up a moment upon rotation or // upon return from detail view controllers. [self.tabBarController.tabBar setHidden:YES]; // Hiding alone is not sufficient. Hiding alone would leave us with an unusable black // bar on the bottom of the size of the tab bar. // We need to enlarge the tab bar controller's view by the height of the tab bar. // Doing so the tab bar, although hidden, appears just beneath the screen. // As the tab bar controller's view works in device coordinations, we need to enlarge // it by the tab bar height in the appropriate direction (height in portrait and width in landscape) // and in reverse/upside down orientation we need to shift the area's origin beyond zero. switch (delegate.tabBarController.interfaceOrientation) { case UIInterfaceOrientationPortrait: // Easy going. Just add the space on the bottom. [self.tabBarController.view setFrame:CGRectMake(0,0,width,height+kTabBarHeight)]; break; case UIInterfaceOrientationPortraitUpsideDown: // The bottom is now up! Add the appropriate space and shift the rect's origin to y = -49 [self.tabBarController.view setFrame:CGRectMake(0,-kTabBarHeight,width,height+kTabBarHeight)]; break; case UIInterfaceOrientationLandscapeLeft: // Same as Portrait but add the space to the with but the height [self.tabBarController.view setFrame:CGRectMake(0,0,width+kTabBarHeight,height)]; break; case UIInterfaceOrientationLandscapeRight: // Similar to Upside Down: Add the space and shift the rect. Just use x and with this time [self.tabBarController.view setFrame:CGRectMake(0-kTabBarHeight,0,width+kTabBarHeight,height)]; break; default: break; } } else { // reset everything to its original state. [self.tabBarController.view setFrame:CGRectMake(0,0,width,height)]; [self.tabBarController.tabBar setHidden:NO]; } return; } - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{ // It is important to call this method at all and to call it here and not in willRotateToInterfaceOrientation // Otherwise the tab bar will re-appear. [self hideTabBar:YES]; // You may want to re-arrange any other views according to the new orientation // You could, of course, utilize willRotateToInterfaceOrientation instead for your subViews. } - (void)viewWillAppear: (BOOL)animated { // In my app I want to hide the status bar and navigation bar too. // You may not want to do that. If so then skip the next two lines. self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent; [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide]; [self hideTabBar: YES]; // You may want to re-arrange your subviews here. // Orientation may have changed while detail view controllers were visible. // This method is called upon return from pushed and pulled view controllers. return; } - (void)viewWillDisappear: (BOOL)animated { // This method is called while this view controller is pulled // or when a sub view controller is pushed and becomes visible // Therefore the original settings for the tab bar, navigation bar and status bar need to be re-instated [self hideTabBar:NO]; // If you did not change the appearance of the navigation and status bar in viewWillAppear, // then you can skip the next two statements too. self.navigationController.navigationBar.barStyle = UIBarStyleBlack; [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide]; return; } 

在线评论应解释每个陈述的推理。 虽然,可能有更聪明的方法来编码它。

隐藏状态栏和导航栏有一个副作用,我不想隐藏你们。 1.当从此导航控制器返回到呼叫导航控制器时,呼叫控制器上的状态栏和导航栏将重叠,直到设备旋转一次,或者在另一个选项卡出现之前再次select相关选项卡时为止。 2.当调用视图控制器是一个表格视图,并且当设备处于横向模式时,当返回到表格时,表格以适合风景的方向显示,但是它被排列成纵向。 左上angular是好的,但是一些表格单元格和标签栏隐藏在屏幕下方。 在右边有一些自由空间。 这也是通过再次旋转设备来固定的。

一旦我find了解决这些小问题但是令人讨厌的错误,我会保持更新。

以下是你如何得到这个工作:

Application Delegate创buildUITabBarController 。 然后,在特定的选项卡中创build一个UINavigationController ,并将其根控制器作为所需的视图控制器。 然后将UINavigationController插入到UITabBarController的“ viewControllers ”数组中。 像这样:

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

这样,你可以在该UINavigationController中的任何视图控制器中将“ hidesBottomBarWhenPushed ”属性设置为“ YES ”,它将隐藏UITabBar

希望有所帮助!

当使用故事板时,其易于设置的视图控制器将隐藏在推动上的标签栏,在目标视图控制器上,只需选中此checkbox:
在这里输入图像描述

我会在这里让我的解决scheme:

 #define FRAME_HIDDEN CGRectMake(0, 0, 768, 1073) //1073 = 1024 (screen) + 49 (UITabBar) #define FRAME_APPEAR CGRectMake(0, 0, 768,1024) -(void) setHidden: (BOOL) hidden{ CGRect frame = (hidden)? FRAME_HIDDEN : FRAME_APPEAR; [self.tabBarController.view setFrame:frame]; [self.tabBarController.tabBar setHidden:hidden]; } 

在需要的地方调用“setHidden”方法! 我使用这个和'Singleton Pattern',然后我的子视图可以隐藏他的Superview中的UITabBar

事实certificate,如果你设置视图hidesBottomBarWhenPushed:YES它会隐藏酒吧当出现的视图(我的部分)。 我把它分配给UITabBarController ,当你想到它时没有太多的意义。

 [self.view hidesBottomBarWhenPushed:YES]; [super pushViewController:viewController animated:animated]; 

在第一个UIViewController“FirstItemViewController”

  @IBAction func pushToControllerAction(sender: AnyObject) { self.hidesBottomBarWhenPushed = true self.performSegueWithIdentifier("nextController", sender: self) } 

在下一个UIViewController“ExampleViewController”中

  override func willMoveToParentViewController(parent: UIViewController?) { if parent == nil { var viewControllers = self.navigationController!.viewControllers if ((viewControllers[viewControllers.count - 2]).isKindOfClass(FirstItemViewController.self)) { (viewControllers[viewControllers.count - 2] as! FirstItemViewController).hidesBottomBarWhenPushed = false } } } 

看看这个答案https://stackoverflow.com/a/36148064/3078925