2011-08-03 234 views
0

我有一个tabbar控制器。我想隐藏视图中的标签栏,并希望在下一个视图中取消隐藏相同的标签栏。隐藏代码正在为第一个视图工作,但在第二个视图中我隐藏的标签栏不工作..隐藏和取消隐藏tabbar

我的代码:

隐藏:

[[self navigationController] setHidesBottomBarWhenPushed:YES]; 

对于取消隐藏:

[[self navigationController] setHidesBottomBarWhenPushed:NO]; 
+0

请查看以下链接。它可以帮助您显示和隐藏标签栏。 http://stackoverflow.com/questions/1209582/is-it-possible-to-hide-the-tabbar-when-a-button-is-pressed-to-allow-a-full-screen – iOS

回答

1

.H

- (void) hideTabBarOfThisTabbarController:(UITabBarController *) tabbarcontroller withAnimationDuration:(int)duration; 

- (void) showTabBarOfThisTabbarController:(UITabBarController *) tabbarcontroller withAnimationDuration:(int)duration; 

.M

- (void) hideTabBarOfThisTabbarController:(UITabBarController *) tabbarcontroller withAnimationDuration:(int)duration{ 

    [UIView transitionWithView:tabbarcontroller.tabBar duration:duration options: UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations:^(void) { 

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

     } 


    } completion:^(BOOL finished) { 


     NSLog(@"tabbar hidden"); 

    }]; 


} 

- (void) showTabBarOfThisTabbarController:(UITabBarController *) tabbarcontroller withAnimationDuration:(int)duration{ 


    [UIView transitionWithView:tabbarcontroller.tabBar duration:duration options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations:^(void) { 



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


     } 


    } completion:^(BOOL finished) { 


     NSLog(@"tabbar shown"); 

    }]; 


    //u can call like this 

    //[self hideTabBarOfThisTabbarController:self.tabBarCon withAnimationDuration:3]; 

    //if u want immediately hide/show the tabbar then duration should be 0.0 
+1

请**停止**在没有上下文的情况下倾销相同的代码块。 –

+0

@Tim Post我花了大约3个小时才使这个工作。所以我分享了这一切,他们谁可以得到有关我的answer.ok通知我不会再重复一遍。我忘了只是通过link.sorry .i不会再犯这个错误 –

+2

你可以在评论中传递链接,这很好。还请为此答案添加一些上下文,现在它只是一个代码转储,可能会让人忽视其有用性。 –