When using hidesBottomBarWhenPushed, i want the tab bar to reappear when i push another view

前端 未结 6 1195
南方客
南方客 2020-12-06 11:09

I have a navigation controller. For one of the views i want to hide the bottom tab bar, so it gets the max possible screen real estate. To do this, i have:

-         


        
6条回答
  •  太阳男子
    2020-12-06 11:42

    I'm have solved this problem like that:

    Almost all my ViewControllers are children of BaseViewController.

    So, example:

    class BaseVC: UIViewController {
        final override var hidesBottomBarWhenPushed: Bool {
            get {
                if navigationController?.viewControllers.last == self {
                    return prefersBottomBarHidden ?? super.hidesBottomBarWhenPushed
                } else {
                    return false
                }
            } set {
                super.hidesBottomBarWhenPushed = newValue
            }
       }
       private(set) var prefersBottomBarHidden: Bool?
    }
    

    Just override variable "prefersBottomBarHidden" in ViewController where BottomBar should be hidden:

    override var prefersBottomBarHidden: Bool? { return true }
    

提交回复
热议问题