Duck
Duck

Reputation: 35953

UINavigationBar popping in and out instead of sliding

I have a navigation based app with 2 controllers: vA and vB.

vA is the navigation controller's root view controller and it is a full screen controller, so when this controller is being shown, the navigation bar is hidden.

Then I push vB using

[self.navigationController pushViewController:vB animated:YES];

On vB's viewDidLoad I have this:

self.navigationController.navigationBarHidden = NO;
// then I have navigation buttons defined here

The animation of vB entering the screen from the right happens this way:

  1. the navigationBar suddenly appears on vA
  2. vB slides from the right and fills the screen.

when I pop vB out, this is what happens

  1. vB slides to the left showing vA behind.
  2. at this time, we see vA with the navigationBar visible on top. Remembers vA should have no navigation bar visible. Then, that navigation vanishes and vA resizes to full screen.

this animation has no grace, is terrible, clunky and wrong.

What I want is this: the navigation slides in and out together with vB.

how do I do that?

thanks.

Upvotes: 0

Views: 345

Answers (2)

user427969
user427969

Reputation: 3896

Try the following:

- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [super viewWillAppear:animated];
}

- (void)viewDidDisappear:(BOOL)animated {
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    [super viewDidDisappear:animated];
}
// OR viewWillDisappear as mentioned by @RubberDuck

Instead of hiding navigation bar in viewDidLoad, implement viewWillAppear and viewDidDisappear

Upvotes: 1

rdelmar
rdelmar

Reputation: 104082

You need to use the animated version of the method you used in vcB's viewDidLoad:

[self.navigationController setNavigationBarHidden:NO animated:YES];

After edit: It seems to work fine in either viewDidLoad or viewWillAppear (but not viewDidAppear). It needs to be in viewWillDisappear for going back.

Upvotes: 2

Related Questions