码迷,mamicode.com
首页 > 其他好文 > 详细

隐藏TabBar的一些方法小结(适用与各种情况)

时间:2016-04-08 21:22:28      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

[cpp] view plain copy
 
  1. 在项目中经常遇到隐藏tabBar,实力很多种方法,可以解决不同情况下问题  
  2.   
  3. 使用中涉及到view的层次关系,下面的使用方法 1、2不做说明;在使用3、4方法时注意要在tabBar所在的rootView中调用实现(必要时使用委托,已达到所需要的目的)  
  4. 举例:A(rootView 是tabBarCtroller);B(A的subView);C(B通过pushViewController)  
  5. 如果想要C出现的时候将tabView隐藏(且C是全屏的,能展开到tabbar存在的位置),B显示的时候babView在显示出来  
  6. 此情况明显1、2方法不能实现了,要用3、4的方法来实现;  
  7. 实现方式:B在pushViewController的时候调用其委托函数(即B消失C出现时tabbar隐藏)  
  8. if([delegaterespondsToSelector:@selector(hidenTabbar:)])  
  9. {  
  10.     [delegatehidenTabbar:YES];  
  11. }  
  12. 在A中实现B的委托代码就是3、4;  
  13. 同样在B的viewWillAppear中也调用其委托:NO;(B显示时tabbar出现)  
  14. -(void)viewWillAppear:(BOOL)animated  
  15. {  
  16.     if([delegate respondsToSelector:@selector(hidenTabbar:)])  
  17.     {  
  18.         [delegatehidenTabbar:NO];  
  19.     }  
  20. }  
  21.   
  22. 1://隐藏tabBar  
  23. WebViewController *webVc = [[WebViewController alloc] init];  
  24. webVc.hidesBottomBarWhenPushed = YES;  
  25. [self.navigationController pushViewController:webVc animated:YES];  
  26. webVc.hidesBottomBarWhenPushed = NO;  
  27. [webVc release];  
  28.   
  29. 2.系统方法    self.hidesBottomBarWhenPushed = YES;  
  30.   
  31.   
  32. 3:自定义tabBar时候,由tabBarController管理的  
  33. //隐藏tabBar  
  34. - (void) hideTabBar:(BOOL) hidden{  
  35.       
  36.     [UIView beginAnimations:nil context:NULL];  
  37.     [UIView setAnimationDuration:0];  
  38.       
  39.     for(UIView *view in self.tabBarController.view.subviews)  
  40.     {  
  41.         if([view isKindOfClass:[UITabBar class]])  
  42.         {  
  43.             if (hidden) {  
  44.                 [view setFrame:CGRectMake(view.frame.origin.x, iphone5?568:480, view.frame.size.width, view.frame.size.height)];  
  45.             } else {  
  46.                 [view setFrame:CGRectMake(view.frame.origin.x, iphone5?568-49:480-49, view.frame.size.width, view.frame.size.height)];  
  47.             }  
  48.         }  
  49.         else  
  50.         {  
  51.             if (hidden) {  
  52.                 [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, iphone5?568:480)];  
  53.             } else {  
  54.                 [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width,  iphone5?568-49:480-49)];  
  55.             }  
  56.         }  
  57.     }  
  58.       
  59.     [UIView commitAnimations];  
  60. }  
  61.   
  62. //调整子视图  
  63. for (UIView *subView in self.view.subviews) {  
  64.     if ([subView isKindOfClass:NSClassFromString(@"UITransitionView")]) {  
  65.         //调整子视图的高度,UITransitionView视图为UINavitaionController的根视图  
  66.         //            subView.frame = CGRectMake(subView.frame.origin.x, subView.frame.origin.y, subView.frame.size.width, 480);  
  67.           
  68.         CGRect frame = subView.frame;  
  69.         frame.size.height = 480;  
  70.         subView.frame = frame;  
  71.     }  
  72. }  
  73.   
  74. 4:类似方法3  
  75. - (void)makeTabBarHidden:(BOOL)hide  
  76. {  
  77.     if ( [self.tabBarController.view.subviews count] < 2 )  
  78.     {  
  79.         return;  
  80.     }  
  81.     UIView *contentView;  
  82.       
  83.     if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )  
  84.     {  
  85.         contentView = [self.tabBarController.view.subviews objectAtIndex:1];  
  86.     }  
  87.     else  
  88.     {  
  89.         contentView = [self.tabBarController.view.subviews objectAtIndex:0];  
  90.     }  
  91.     //    [UIView beginAnimations:@"TabbarHide" context:nil];  
  92.     if ( hide )  
  93.     {  
  94.         contentView.frame = self.tabBarController.view.bounds;  
  95.     }  
  96.     else  
  97.     {  
  98.         contentView.frame = CGRectMake(self.tabBarController.view.bounds.origin.x,  
  99.                                        self.tabBarController.view.bounds.origin.y,  
  100.                                        self.tabBarController.view.bounds.size.width,  
  101.                                        self.tabBarController.view.bounds.size.height - self.tabBarController.tabBar.frame.size.height);  
  102.     }  
  103.       
  104.     self.tabBarController.tabBar.hidden = hide;  
  105. }  

隐藏TabBar的一些方法小结(适用与各种情况)

标签:

原文地址:http://www.cnblogs.com/dzhs/p/5369717.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!