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

后端 未结 16 1614
广开言路
广开言路 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:00

    Here is my solution (my tab view controller is inside navigation controller for good measure)... So I have subclassed UITabBarController and did this... exposing -setTabBarHidden: method

    - (void)setTabBarHidden:(BOOL)hidden {
        _tabBarHidden = hidden;
    
        [UIView performWithoutAnimation:^{
            [self adjustViews];
        }];
    
    }
    
    - (void)adjustViews {
        if ( _tabBarHidden ) {
            CGRect f = self.tabBar.frame;
    
            // move tab bar offscreen
            f.origin.y = CGRectGetMaxY(self.view.frame);
            self.tabBar.frame = f;
    
            // adjust current view frame
            self.selectedViewController.view.frame = self.view.frame;
        } else {
            CGRect f = self.tabBar.frame;
    
            // move tab bar on screen
            f.origin.y = CGRectGetMaxY(self.view.frame) - (CGRectGetMaxY(self.tabBar.bounds) + CGRectGetMaxY(self.navigationController.navigationBar.frame));
            self.tabBar.frame = f;
    
            // adjust current view frame
            f = self.view.bounds;
            f.size.height -= CGRectGetMaxY(self.tabBar.bounds);
            self.selectedViewController.view.frame = f;
        }
    }
    
    - (void)viewWillLayoutSubviews {
        [super viewWillLayoutSubviews];
    
        [UIView performWithoutAnimation:^{
            [self adjustViews];
        }];
    }
    
    - (void)viewDidLayoutSubviews {
        [super viewDidLayoutSubviews];
    
        [UIView performWithoutAnimation:^{
            [self adjustViews];
        }];
    }
    

提交回复
热议问题