How to hide UITabBar?

前端 未结 4 1635
孤独总比滥情好
孤独总比滥情好 2020-12-02 20:21

In my app I have a tab bar. And in some views I as well have a toolbar. So when I come to those views with a toolbar it looks ugly - two bars at the bottom of the view. I th

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 20:57

    Don't use this solution!

    BOOL hiddenTabBar;
    UITabBarController *tabBarController;
    
    - (void) hideTabBar {
    
         [UIView beginAnimations:nil context:NULL];
         [UIView setAnimationDuration:0.4];
         for(UIView *view in tabBarController.view.subviews)
         {
              CGRect _rect = view.frame;
              if([view isKindOfClass:[UITabBar class]])
              {
                   if (hiddenTabBar) {
                        _rect.origin.y = [[UIScreen mainScreen] bounds].size.height-49;
                        [view setFrame:_rect];
                   } else {
                        _rect.origin.y = [[UIScreen mainScreen] bounds].size.height;
                        [view setFrame:_rect];
                   }
              } else {
                   if (hiddenTabBar) {
                        _rect.size.height = [[UIScreen mainScreen] bounds].size.height-49;
                        [view setFrame:_rect];
                   } else {
                        _rect.size.height = [[UIScreen mainScreen] bounds].size.height;
                        [view setFrame:_rect];
                   }
              }
         }    
         [UIView commitAnimations];
    
         hiddenTabBar = !hiddenTabBar;
    }
    

    Source

提交回复
热议问题