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.
答案 0 :(得分:25)
您应该从标签栏控制器中显示新的viewController:
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)
})
}
答案 1 :(得分:4)
在Swift 5中,
let popupController = ViewController()
popupController.modalPresentationStyle = .overFullScreen
self.present(popupController, animated: true, completion: nil)