Hide UITabBar in UITabBarController with autolayout

344 Views Asked by At

I'm trying to hide the tab bar from within a UITabBarController.

This successfully hides the tab bar:

self.tabBar.hidden = true

However, I now have a black "blank spot" where the tab bar used to be.

I've seen some solutions to this problem on SO, but they modified the frames directly, and didn't take into autolayout.

How can I stretch the main view to fill the rest of the screen, with autolayout?

2

There are 2 best solutions below

0
On

Often times its because, the controllers view is not allowed to extend under the bottom bar. You can enable this by

self.edgesForExtendedLayout = UIRectEdgeBottom;
0
On

The viewcontroller in which you wish to hide the tabbar should override the variable:

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

It will take care of your bottom autolayouts too and adjusts the empty space in bottom as well.