In my project I have a UITabBarController
. And on one of it's ViewControllers
I have button. When I click this button, a new ViewController
is presenting modally.
The problem is, when the second VC is presenting, tabBarController
's tabBar
is still visible. When I try to hide it in first ViewController
's action openFiltersList()
with this method:
self.tabBarController?.tabBar.hidden = true
it hides, but when I'm trying to unhide it, when I dismiss second VC, setting this parameter to false
doesn't work, tabBar
stays hidden.
Here's the code for first and second:
First (InvitesViewController
, one of the tabBarController's View Controllers):
func openFiltersList() {
var filtersView : UIViewController = self.storyboard?.instantiateViewControllerWithIdentifier("filtersViewController") as! FiltersViewController
filtersView.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
self.presentViewController(filtersView, animated: true) { () -> Void in
UIView.animateWithDuration(0.3, animations: { () -> Void in
filtersView.view.backgroundColor = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 0.5)
})
}
self.tabBarController?.tabBar.hidden = true
}
Second (FiltersViewController
, not embedded anywhere):
@IBAction func dismiss(sender: AnyObject) { // close button action
self.dismissViewControllerAnimated(true, completion: nil)
var destinationVC : UIViewController = self.storyboard?.instantiateViewControllerWithIdentifier("invitesViewController") as! InvitesViewController
destinationVC.tabBarController?.tabBar.hidden = false
}
I'm using storyboard for interface.
Simply, Go to ViewController (in StoryBoard) -> Attribute inspector -> Under 'View Controller' section select 'Hide Bottom Bar on Push' checkbox.
To add the new View Controller to the Tab Bar Controller, right-click the Tab Bar Controller and drag it to the new View Controller. Select Relationship Segue. Now, the Tab Bar Controller has the third item and Relationship “view controllers” to “View Controller”.
If you don't want that behavior, you should set hidesBottomBarWhenPushed to true where applicable. This will hide the tab bar along with any toolbars you had showing, but only when a view controller is pushed onto the navigation stack. This allows you to show the tab bar at first, then hide it when you need more room.
The tab bar interface displays tabs at the bottom of the window for selecting between the different modes and for displaying the views for that mode. This class is generally used as-is, but may also be subclassed. Each tab of a tab bar controller interface is associated with a custom view controller.
In Swift 5,
let popupController = ViewController()
popupController.modalPresentationStyle = .overFullScreen
self.present(popupController, animated: true, completion: nil)
You should present the new viewController from tab bar controller:
self.tabBarController?.presentViewController(filtersView, animated: true) { () -> Void in
UIView.animateWithDuration(0.3, animations: { () -> Void in
filtersView.view.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5)
})
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With