How to hide UITabBarController programmatically?

前端 未结 5 1691
小蘑菇
小蘑菇 2020-12-05 15:46

Is it possible to hide it with animation ?

5条回答
  •  长情又很酷
    2020-12-05 16:22

    Another Solution I use: Call Methods When You Want to Hide Menu:

    //Show Tab Bar
    [self showTabBar:self.tabBarController];
    //If You Want to Hide/Show Navigation Bar Also
    [self.navigationController setNavigationBarHidden: NO animated:YES];
    
    //Hide Tab Bar
    [self hideTabBar:self.tabBarController];  
    //If You Want to Hide/Show Navigation Bar Also
    [self.navigationController setNavigationBarHidden: YES animated:YES];
    

    Methods:

    - (void)hideTabBar:(UITabBarController *) tabbarcontroller
    {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    
    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)];
        }
    }
    
    [UIView commitAnimations];
    }
    
    - (void)showTabBar:(UITabBarController *) tabbarcontroller
    {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    
    for(UIView *view in tabbarcontroller.view.subviews)
    {
        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)];
         }
    }
    
    [UIView commitAnimations];
    }
    

提交回复
热议问题