navigation bar disappear faster than the view when use popToRootViewControllerAnimated:YES

1.4k views Asked by At

I have a root vc embed in the navigation vc, I set the navigation bar hidden using
[self.navigationController setNavigationBarHidden:YES];
It works fine, the navigation bar disappears.

And push the 2nd vc use
[self.navigationController pushViewController:controller animated:YES];
In the 2nd vc set the navigation bar display. Everything goes well.

So when I clicked the 'back button' on the navigation bar, I found the navigation bar disappeared faster than the view, especially set the view's background to black, I can see the whole view is black just like there're not any navigation bar ever.
I don't want this, I just hope the navigation bar will always present until the viewDidDisappear.

Here is a picture of the problem

I use [self.navigationController popViewControllerAnimated:YES]; and must fill the Animated is YES can reproduce this appearance.

For the sort,

  1. Two vc in the navigation vc.
  2. Root vc's navigation bar was hidden,the 2nd VC pushed from the root vc.
  3. The 2nd vc made the navigation bar display.
  4. Use [self.navigationController popViewControllerAnimated:YES] to back.

Where is the code location:
ps:whatever how you set the navigation bar's hidden-property, in ViewDidLoad or ViewWillAppear or ViewDidAppear or other place, they are all the same appearance.

in the root vc's viewDidLoad
[self.navigationController setNavigationBarHidden:YES];

and root vc's didSelectRowAtIndexPath:
[self.navigationController setNavigationBarHidden:NO];

4

There are 4 answers

0
suydea On BEST ANSWER

Where is Wrong

  • The RootView and SubView are in the same NavigationController hierarchy.This means the navigationBar neither belong to the RootView nor to the SubView.
  • The navigationBar is global and unique in this situation . You can't deal with the two view's display only using one navigationBar.

How to solve

  • In the SubView, I make a new navigationBar to replace the exiting one, and add it to the SubView's subview. It works well.
0
Thuy On

You should move [self.navigationController setNavigationBarHidden:NO]; to your subVC's viewWillAppear: and move [self.navigationController setNavigationBarHidden:YES]; to your RootView's viewWillAppear:

3
Ashutosh On

Frome ViewDidLoad, move [self.navigationController setNavigationBarHidden:YES]; in ViewDidAppear method. It will work.

2
an0 On

You just need to move the call of setNavigationBarHidden:Yes from 2nd vc's viewWillDisappear: to root vc's viewDidAppear:.

I know visually this is not pleasant. I just gave you what you said you wanted: "I just hope the navigation bar will always present until the viewDidDisappear." For a nice transition you need to use custom transition.