Hide tab bar in IOS swift app

后端 未结 8 2200
走了就别回头了
走了就别回头了 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:27

    Swift 3.

    self.tabBarController?.tabBar.isHidden = true
    
    0 讨论(0)
  • 2020-12-22 19:35

    Before push set controller.hidesBottomBarWhenPushed = true

    let objCreateEventVC = CreateEventVC()
    objCreateEventVC.hidesBottomBarWhenPushed = true
    self.navigationController?.pushViewController(objCreateEventVC, animated: false)
    
    0 讨论(0)
  • 2020-12-22 19:39

    You can also set it in extension (use Dharmesh Kheni answer)

    extension UITabBar {
    func tabsVisiblty(_ isVisiblty: Bool = true){
        if isVisiblty {
            self.isHidden = false
            self.layer.zPosition = 0
        } else {
            self.isHidden = true
            self.layer.zPosition = -1
        }
    }
    
    0 讨论(0)
  • 2020-12-22 19:44

    You can simply use this in your ViewDidLoad() method.

    self.tabBarController?.tabBar.hidden = true
    

    For Swift 3.0, 4.0, 5.0:

    self.tabBarController?.tabBar.isHidden = true
    

    Or you can change z position of tab bar this way:

    self.tabBarController?.tabBar.layer.zPosition = -1
    

    and if you want to show it again then:

    self.tabBarController?.tabBar.layer.zPosition = 0
    
    0 讨论(0)
  • 2020-12-22 19:44

    No need to set tabBar's isHidden property.

    Simply, Go to ViewController (in StoryBoard) -> Attribute inspector -> Under 'View Controller' section select 'Hide Bottom Bar on Push' checkbox. This works like a charm.

    If you go the 'isHidden' way you need to do a lot of handling, i.e. to make it appear again when you go back and also to remove the bottom empty space after hiding tabBar.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题