【问题标题】:UITabBar wont hideUITabBar 不会隐藏
【发布时间】:2011-08-08 01:42:21
【问题描述】:

我在 UITabBarController 中有一个 UINavigationController,我似乎无法隐藏推送的 viewController 的 tabBar。

我使用下面的代码来隐藏它:

在它被推送之前:

tpsv.hidesBottomBarWhenPushed = YES; tpsv.tabBarController.hidesBottomBarWhenPushed = YES;

viewWillAppear:

self.tabBarController.tabBar.hidden = YES;

AppDelegate *del = (AppDelegate *)[[UIApplication sharedApplication] delegate];

[[[del tabController] tabBar]setHidden:YES];

但以上都不起作用。

如果你能告诉我如何解决这个问题,那就太好了。

【问题讨论】:

    标签: iphone objective-c uinavigationcontroller uitabbarcontroller uitabbar


    【解决方案1】:

    在推送新的视图控制器之前设置它:

    MyViewController *myVC = [[[MyViewController alloc] init] autorelease];
    myVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:myVC animated:YES];
    

    [编辑:评论重新使用]

    刚刚注意到你说你试过这个。不确定在推送 VC 或配置它的上下文中您还在做什么,但这确实可以正常工作。这就是我在我的应用程序中做这件事的方式。

    【讨论】:

      【解决方案2】:
      - (void) hideTabBar:(UITabBarController *) tabbarcontroller {
      
      
          [UIView beginAnimations:nil context:NULL];
          [UIView setAnimationDuration:0.5];
          for(UIView *view in tabbarcontroller.view.subviews)
          {
              if([view isKindOfClass:[UITabBar class]])
              {
                  [view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
              } 
              else 
              {
                  [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
              }
      
          }
      
          [UIView commitAnimations];
      
      
      
      
      
      }
      
      - (void) showTabBar:(UITabBarController *) tabbarcontroller {
      
          [UIView beginAnimations:nil context:NULL];
          [UIView setAnimationDuration:0.5];
          for(UIView *view in tabbarcontroller.view.subviews)
          {
              NSLog(@"%@", view);
      
              if([view isKindOfClass:[UITabBar class]])
              {
                  [view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
      
              } 
              else 
              {
                  [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
              }
      
      
          }
      
          [UIView commitAnimations]; 
      }
      

      【讨论】:

      • 你可以把这些函数放在一些全局文件中,你只需要调用 hide 函数来隐藏 tabbarcontroller.. 和 show 函数来显示 tabbarcontroller... 你可以调用这些方法,如 - [commonFunctions hideTabBar:self.tabbarcontroller];
      • 我在无法隐藏的viewController中试过了,也可以。
      【解决方案3】:

      我也遇到过同样的问题

      myVC.hidesBottomBarWhenPushed = YES;
      

      它不会在后续视图中删除标签栏。可能它已被弃用。您不应该使用 setHidesBottomBarWhenPushed: 命令面对这个问题。尝试使用以下视图:

      MyViewController *myVC = [[[MyViewController alloc] init] autorelease];
      [myVC setHidesBottomBarWhenPushed:YES];
      [self.navigationController pushViewController:myVC animated:YES];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-08-24
        • 1970-01-01
        • 2011-11-17
        • 2010-10-15
        • 2011-12-03
        • 2011-07-13
        • 1970-01-01
        相关资源
        最近更新 更多