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 }

 

相关文章:

  • 2021-03-30
  • 2021-11-03
  • 2021-12-28
  • 2022-12-23
  • 2021-11-10
猜你喜欢
  • 2022-01-07
  • 2021-11-17
  • 2019-10-12
  • 2022-03-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案