How to hide parent tabbar when pushing controller in navigationController

后端 未结 8 632
耶瑟儿~
耶瑟儿~ 2020-12-14 07:06

I have an application with a tab bar controller and each view contains a navigation controller. My MainWindow looks as follows: Image here http://www.freeimagehosting.net/im

相关标签:
8条回答
  • 2020-12-14 07:38

    You can add below code in the view controller, which you are pushing.

    -(BOOL)hidesBottomBarWhenPushed
    { 
         return YES;
    }
    

    This will hide the tabbar in the pushed view controller only and as you pop the view controller tabbar remains unhide in rest all view controllers.

    Swift version (3.x and above)

    override var hidesBottomBarWhenPushed: Bool {
        get {
            return navigationController?.topViewController == self
        }
        set {
            super.hidesBottomBarWhenPushed = newValue
        }
    }
    

    Thanks

    0 讨论(0)
  • 2020-12-14 07:42

    A very simple solution:

     destinationViewController.hidesBottomBarWhenPushed = YES;
    

    In your case:

     articleController.hidesBottomBarWhenPushed = YES;
    

    Hope this helps!

    0 讨论(0)
  • 2020-12-14 07:47

    Use property hidesBottomBarWhenPushed in the controller that you want to hide.

    For hide, all controllers put into prepare for segue

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        segue.destination.hidesBottomBarWhenPushed = true
    }
    
    0 讨论(0)
  • 2020-12-14 07:49

    for swift 3,write the same code by you unhide the tabbar before pushviewController code like below

       var frame = self.tabBarController?.tabBar.frame
        frame?.origin.y = self.view.frame.size.height - (frame?.size.height)!+112
        UIView.animate(withDuration: 0.2, animations: {
            self.tabBarController?.tabBar.frame = frame!
        })
        self.navigationController?.pushViewController(viewController, animated: true)
    

    or use just whant to unhide the tabbar u can use

      viewController.hidesBottomBarWhenPushed = false
    
    0 讨论(0)
  • 2020-12-14 07:53

    enter image description here

    Go to interface builder in Xcode -> open attribute inspector and check the item 'Hide Bottom bar on Push' for view controller you don't want to show tab bar. It will work!!

    0 讨论(0)
  • 2020-12-14 08:00

    If you prefer storyboard configuration over coding there is a toggle for that. Just go destinationViewController > Attribute Inspector:

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