FS.O6
FS.O6

Reputation: 1464

Pushing UIViewController above UITabBar

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:

Imafe

Code:

self.navigationController?.pushViewController(detailVC, animated: true)

Thank you!

Upvotes: 4

Views: 5131

Answers (6)

yoAlex5
yoAlex5

Reputation: 34225

iOS UINavigationViewController and UITabBar

You have three options:

  1. in storyboard: select ViewController -> Attributes Inspector -> Hide Bottom Bar On Push

  2. in code: vc.hidesBottomBarWhenPushed

  3. in ViewController code:

public override var hidesBottomBarWhenPushed: Bool {
    get { return true }
    set { }
}

Upvotes: 0

Priyank Patel
Priyank Patel

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)

enter image description here

Upvotes: 2

FS.O6
FS.O6

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

Shezad
Shezad

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

iVarun
iVarun

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:

enter image description here

Upvotes: 9

pacification
pacification

Reputation: 6018

Go to storyboard and check the Hide Bottom Bar On Push:

enter image description here

or just type in DeatilVC viewDidLoad method hidesBottomBarWhenPushed = true.

Upvotes: 0

Related Questions