Max
Max

Reputation: 2749

iOS - UINavigationController - NavigationBar sliding in together with UIViewController

I have two UIViewControllers, A and B.

A is hiding the UINavigationBar and B is not. When animating (with the default animation) from A to B, the navigation bar has to become visible. The navigation bar just pops in at some point (viewWillAppear or viewDidAppear) instead of sliding in with the UIViewController B.

When going back from B to A, the navigation bar is smoothly sliding back out.

How can I achieve the desired effect when animating from A to B?

Upvotes: 2

Views: 181

Answers (2)

Max
Max

Reputation: 2749

In ViewController B, one has to simply do:

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

I wasn't aware that this also controls the animation while doing a full view controller transition. I thought it only controls animation the navigation bar out to the top and back in.

Upvotes: 1

Horray
Horray

Reputation: 693

You can try the following:

Use a instance variable to do this:

self.navigationController setNavigationBarHidden:hide animated:animated];
_shouldHideStatusBar = hide;

And implement the following function:

- (BOOL)prefersStatusBarHidden{
    return _shouldHideStatusBar;
}

The setNavigationBarHidden:animated function will automatically call prefersStatusBarHidden function. If it doesn't you can call it with the following UIViewController's method:

[self setNeedsStatusBarAppearanceUpdate];

And of course you can choose your status bar hiding animation style with:

- (UIStatusBarAnimation) preferredStatusBarUpdateAnimation {
    return UIStatusBarAnimationSlide;
}

Let me know if this helps. Good luck!!

(I got this answer here: How to slide in/out statusBar and navigationBar simultaneously?)

Upvotes: 0

Related Questions