Iphone: Is it possible to hide the TabBar? (Pre-iOS 8)

后端 未结 16 1644
广开言路
广开言路 2020-12-05 04:23

I have an application that uses a UITabBarController to switch between modes. When in a certain mode, I\'d like to hide the tab bar until the steps of that mode

16条回答
  •  再見小時候
    2020-12-05 05:03

    You can create Tabbar Category and show/Hide easily. and you can access full view.

    create category #import "UITabBarController+HideTabBar.h"

    @implementation UITabBarController (HideTabBar)
    
    - (void)hideTabBarAnimated:(BOOL)animated
    {
        CGRect statusbarFrame = [UIApplication sharedApplication].statusBarFrame;
        CGRect tabBarControllerFrame = self.view.frame;
        if (statusbarFrame.size.height>20)
        {
            tabBarControllerFrame.size.height =  screenSize.size.height + self.tabBar.frame.size.height - 20.0;
        }
        else
        {
            tabBarControllerFrame.size.height = screenSize.size.height + self.tabBar.frame.size.height ;
        }
    
        if (animated) {
            [UIView animateWithDuration:0.2 animations:^{
                [self.view setFrame:tabBarControllerFrame];
            } completion:^(BOOL finished) {
    
            }];
        }
        else
            [self.view setFrame:tabBarControllerFrame];
    }
    
    - (void)showTabBarAnimated:(BOOL)animated {
        CGRect statusbarFrame = [UIApplication sharedApplication].statusBarFrame;
        CGRect tabBarControllerFrame = self.view.frame;
        if (statusbarFrame.size.height>20)
        {
            tabBarControllerFrame.size.height =  screenSize.size.height - 20.0;
        }
        else
        {
            tabBarControllerFrame.size.height = screenSize.size.height ;
        }
    
        if (animated) {
            [UIView animateWithDuration:0.2 animations:^{
                [self.view setFrame:tabBarControllerFrame];
            } completion:^(BOOL finished) {
    
            }];
        }
        else
            [self.view setFrame:tabBarControllerFrame];
    }
    @end
    

    Note : use statusbarFrame is used when hotspot or call is ON so tabbar would not cut down.

    Now Import category in which you class you want to use methods and just call below methods to hide or show tabbar.

    [self.tabBarController hideTabBarAnimated:YES];
    
    [self.tabBarController showTabBarAnimated:YES];
    

    Hope this Helps.

提交回复
热议问题