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

前端 未结 6 1194
南方客
南方客 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:43

    Case one: To hide UITabbarController in a cetain UIVIewController, for example while calling self.performSegueWithIdentifier("Identifier", sender: self), it is necesssary prior to to that, set self.hidesBottomBarWhenPushed = true flag. And after self.hidesBottomBarWhenPushed = false flag. But we have to understad that through one UIViewController, UITabbarController will re-appear and, in case if you need to use UITabbarController with single UIViewControler, it wont yield right result.

    in the FirstItemViewController

        @IBAction func pushToControllerAction(sender: AnyObject) {
            self.hidesBottomBarWhenPushed = true
            self.performSegueWithIdentifier("nextController", sender: self)
            self.hidesBottomBarWhenPushed = false
        }
    

    Case Two: To hide UITabbarController in a certain UIVIewController, after which a UITabbarController should be popped, it is necessary, for example, while calling self.performSegueWithIdentifier("nextController", sender: self) , to set self.hidesBottomBarWhenPushed = true before the method. Alse willMoveToParentViewController(parent: UIViewController?) in the method should be configured as it shown in the code example.

    in the first UIViewController "FirstItemViewController"

     @IBAction func pushToControllerAction(sender: AnyObject) {
         self.hidesBottomBarWhenPushed = true
         self.performSegueWithIdentifier("nextController", sender: self)
     }
    

    in the next UIViewController "ExampleViewController"`

     override func willMoveToParentViewController(parent: UIViewController?) {
             if parent == nil {
                 var viewControllers = self.navigationController!.viewControllers
                 if ((viewControllers[viewControllers.count - 2]).isKindOfClass(FirstItemViewController.self)) {
                     (viewControllers[viewControllers.count - 2] as! FirstItemViewController).hidesBottomBarWhenPushed = false
                 }
             }
     }
    

    Swift 3 code:

    let viewControllers = self.navigationController!.viewControllers
                    if ((viewControllers[viewControllers.count - 2]) is (FirstItemViewController)) {
                        (viewControllers[viewControllers.count - 2] as! FirstItemViewController).hidesBottomBarWhenPushed = false
                    }
    

    Test project

提交回复
热议问题