UITabBar的隐藏与显示

1.系统方法  self.hidesBottomBarWhenPushed = YES;

  该方法存在一定缺陷,根据其名字可以发现,只有在push的时候才会生效,也就是说在UITabBarControllerUINavigationController结合使用的时候能用。

2.第二种方法比较通用,原理也很简单。

  修改 TabBar 的 subview 的 frame 就行了。其中,UITabBarControllersubview 共有两个,一个叫 UITabBar,就是底下的那个 Bar;另一个叫UITranstionview,就是 Bar 上面的视图。这两个 view 下面还有其他的subview,这就不用去管它了。UITabBar的 y 向下移49个单位,把UITranstionview 的 hight 加长 49 个单位。

 1 - (void)hidesTabBar:(BOOL)hidden{
 2     
 3     
 4     [UIView beginAnimations:nil context:NULL];
 5     [UIView setAnimationDuration:0];
 6     
 7     for (UIView *view in self.tabBarController.view.subviews) {
 8         if ([view isKindOfClass:[UITabBar class]]) {
 9             if (hidden) {
10                 [view setFrame:CGRectMake(view.frame.origin.x, [UIScreen mainScreen].bounds.size.height, view.frame.size.width , view.frame.size.height)];
11                
12             }else{
13                 [view setFrame:CGRectMake(view.frame.origin.x, [UIScreen mainScreen].bounds.size.height - 49, view.frame.size.width, view.frame.size.height)];
14                 
15             }
16         }else{
17             if([view isKindOfClass:NSClassFromString(@"UITransitionView")]){
18                 if (hidden) {
19                     [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, [UIScreen mainScreen].bounds.size.height)];
20                     
21                 }else{
22                     [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, [UIScreen mainScreen].bounds.size.height - 49 )];
23                    
24                 }
25             }
26         }
27     }
28     [UIView commitAnimations];
29     
30 }
原文地址:https://www.cnblogs.com/ubersexual/p/2981670.html