Reputation: 1464
I have a UIViewController
called ListVC
. ListVC
has a UITabBar
that the user can switch tabs with. It also has UINavigationController
.
In ListVC
I have a button, that I want to push a new ViewController called DetailVC
when it's pressed (with the NavigationController
). I want to present DeatilVC
without a UITabBar
.
The problem is that when I'm using the pushViewController(animated)
method, the view still has the UITabBar
.
How can I push the view (I don't want to present it modally) above the UITabBar
?
You can see an example of it on Whatsapp
when selecting a chat from the chat list. Image:
Code:
self.navigationController?.pushViewController(detailVC, animated: true)
Thank you!
Upvotes: 4
Views: 5131
Reputation: 34225
iOS UINavigationViewController and UITabBar
You have three options:
in storyboard: select ViewController -> Attributes Inspector -> Hide Bottom Bar On Push
in code: vc.hidesBottomBarWhenPushed
in ViewController code:
public override var hidesBottomBarWhenPushed: Bool {
get { return true }
set { }
}
Upvotes: 0
Reputation: 870
1.Write below code when you push:
let yourVC = Storyboard.Main.storyboard().instantiateViewController(withIdentifier: "YourViewController") as! YourViewController
yourVC.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(yourVC, animated: true)
Upvotes: 2
Reputation: 1464
Ok I've solved the problem. I had to add hidesBottomBarWhenPushed
twice before and after the push code:
self.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(detailVC, animated: true)
self.hidesBottomBarWhenPushed = false
Upvotes: 1
Reputation: 756
try this
override func viewWillDisappear(_ animated: Bool) {
self.tabBarController?.tabBar.isHidden = true
}
override func viewWillAppear(_ animated: Bool) {
self.tabBarController?.tabBar.isHidden = false
}
Upvotes: 0
Reputation: 6611
Write below code when you push:
yourViewController.hidesBottomBarWhenPushed = true
You can also hide tabbar on push from storyboard also. select view controller which you are going to push and check Hide Bottom Bar on Push:
Upvotes: 9
Reputation: 6018
Go to storyboard and check the Hide Bottom Bar On Push
:
or just type in DeatilVC viewDidLoad
method hidesBottomBarWhenPushed = true
.
Upvotes: 0