Eyal
Eyal

Reputation: 10828

Auto Layout and "Hide bottom bar when pushed"

My app's (simplified) structure is this:

UITabBarController with one UINavigationController holding a UITableViewController as root view controller.

when tapping one of the table view controller cells, I push a regular UIViewController (lets call it VC) end hiding the bottom tab bar. (using the "Hide bottom bar when pushed" flag)

In storyboard I added a regular UIView subclass to VC that look like a bottom bar, and I use Auto Layout to pin it to the bottom of the VC view.

The problem
when I push VC it takes a second for this view to pin to the bottom, it looks like auto layout pin it to the bottom as if the tab bar is not hidden and after a sec it recognise that the tab bar is hidden and moves it to the real bottom of the view.

I know its not the best explanation, so I added a very simple project to demonstrate the issue.

Upvotes: 43

Views: 23351

Answers (10)

rdelmar
rdelmar

Reputation: 104082

If you want the tab bar to be hidden, you can add this code to your controller,

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = YES;
}

You will also have to put that code (but passing NO) into the controller where you want the tab bar to be visible. You should also deselect the "Hide bottom bar when pushed" box in IB.

After Edit:

You'll get a better animation if, in the first controller, you animate the alpha value of the non-hidden tab bar from 0 to 1 over a short time. This looks good if you go back with the back button. If you want to use the swipe back, you would have to do something more complicated involving the interactivePopGestureRecognizer.

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = NO;
    self.tabBarController.tabBar.alpha = 0.0;
    [UIView animateWithDuration:.4 animations:^{
        self.tabBarController.tabBar.alpha = 1.0;
    }];
}

Upvotes: 2

Zaporozhchenko Oleksandr
Zaporozhchenko Oleksandr

Reputation: 4928

IF you can't select bottomlayoutguide bottom in your Xcode 7+

like there just do the following: open your storyboard in source code editor

open in editor search your controller's identifier

search in source file find <layoutGuides>, type <bottom>, copy it id

find layoutGuides search by id change attribute from top to bottom

find and replace enjoy.

Upvotes: 6

taitanxiami
taitanxiami

Reputation: 119

set UINavigationBar Translucent with NO.

like this: self.navigationController.navigationBar.translucent = NO;

Upvotes: 1

Breno Morais
Breno Morais

Reputation: 53

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = NO;
    self.tabBarController.tabBar.alpha = 0.0;
    [UIView animateWithDuration:.3 animations:^{
        self.tabBarController.tabBar.alpha = 5.0;
    }];
}

Upvotes: 1

Vincenzo
Vincenzo

Reputation: 1158

The accepted answer did not work for me (the option was not available). However I have found another solution. (based on Hide Bottom Bar When Pushed through Autolayout)

Select booth the view and the object to align (in my case btnShare) and add a new alignment constraint (Bottom Edges).

enter image description here enter image description here

Upvotes: 32

M&#225;rio Carvalho
M&#225;rio Carvalho

Reputation: 3125

In the storyboard, Go to the View Controller that you want to hide the tab bar, click on Attribute Inspector and select Hide bottom bar when pushed. Check image bellow.

storyboard example

Upvotes: 3

Earl Grey
Earl Grey

Reputation: 7466

The problem is with this specific constraint which is between the view and the top of the bottom layout guide.

enter image description here

Select the constraint and edit its "Second Item" property

enter image description here

Here you need to choose bottom

enter image description here

Once you have that, the pink view is not influenced by layout guide anymore. The layout guide seem to acknowledge that the tab bar is hidden only after the root view of the pushed view controller is in the bounds of main screen and this happens only when the animation is finished.

And that is the reason the view hierarchy needs to be laid out again which causes the unwanted animation.

Upvotes: 64

Arash
Arash

Reputation: 1316

Select your "Navigation Controller" and in "Attribute Inspector" remove the checkmark from "Under Bottom Bars".

Upvotes: 6

Karthik Rao
Karthik Rao

Reputation: 226

Try pinning bottom of your view to bottom of superview and not bottom-layout

Upvotes: 0

Onik IV
Onik IV

Reputation: 5047

Hi In storyboard select Tab bar (Is Tab Bar Controller Scene > Tab Bar Controller > Tab Bar ), in the attribute inspector, uncheck Translucent box. This action fix your problem. (But there are many things, "Hide bottom bar when pushed" is to toolbar).

Upvotes: 14

Related Questions