Hide tab bar in IOS swift app

后端 未结 8 2250
走了就别回头了
走了就别回头了 2020-12-22 19:19

I\'m trying to figure out how to hide the tab bar in my iOS swift app. I don\'t care about any fancy animations or anything. Just something I can put in the ViewDidLoad() fu

8条回答
  •  难免孤独
    2020-12-22 19:44

    To hide the navigationBar and the tabBar I use the next function:

    var tabBarHeight : CGFloat!
    
    func fullScreenAction(){
        if navigationController?.isNavigationBarHidden ?? false {
            //Show navigationBar
            navigationController?.setNavigationBarHidden(false, animated: false)
    
            //Show tabBar
            tabBarController?.tabBar.isHidden = false
            //Update the height of tabBar
            if (!(tabBarController?.tabBar.frame.size.height.isEqual(to: 0))!) {
                tabBarHeight = self.tabBarController?.tabBar.frame.size.height
            }
            tabBarController?.tabBar.frame.size.height   = tabBarHeight
        } else {
            //Hide navigationBar
            navigationController?.setNavigationBarHidden(true, animated: false)
    
            //Hide tabBar
            tabBarController?.tabBar.isHidden = true
            //Update the height of tabBar
            tabBarHeight = tabBarController?.tabBar.frame.size.height
            tabBarController?.tabBar.frame.size.height   = 0
    
        }
    
    }
    

    When the screen orientation has changed the height of tabBar change too, so I use the next function to exit of fullscreen to resize the height:

    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransition(to: size, with: coordinator)
        if navigationController?.isNavigationBarHidden ?? false {
            navigationController?.setNavigationBarHidden(false, animated: false)
            tabBarController?.tabBar.isHidden = false
        }
    }
    

    I hope it is useful for you.

提交回复
热议问题