views:

376

answers:

3

I have a toolbar in my RootViewController and I then hide the toolbar in a SubViewController using the following code:

RootViewController

- (void)viewDidLoad {
    ...
    [self.navigationController setToolbarHidden:FALSE animated:FALSE];
    ...
}

- (void)viewDidAppear:(BOOL)animated {
    [self.navigationController setToolbarHidden:FALSE animated:TRUE];
    [super viewDidAppear:animated];
}

SubViewController

- (void)viewDidLoad {
    ...
[self.navigationController setToolbarHidden:YES animated:YES];
    [super viewDidLoad];
}

This all works as expected i.e. the toolbar will be hidden and unhidden using a nice vertical animation when moving from one view to another and back again.

However, there appears to be a nasty animation issue when moving from the RootViewController to the SubViewController. As the toolbar is being hidden, a white bar will appear where the toolbar was, and then quickly disappears across the screen from right to left.

Hopefully I've explained this well enough for you to understand.

Any ideas how to fix this?

+1  A: 

Have you tried doing the animation in SubViewController's -viewWillAppear: method? You may have better luck there.

Jeff Kelley
This worked perfectly, thanks.
redspike
No problem. Just be sure to call [super viewWillAppear:animated] at some point in there.
Jeff Kelley
A: 

You can (probably should) do this in the subview controller's designated initializer, e.g. initWithNibName:bundle:

mvl
A: 

I have seen this problem a couple of times and I have found that putting the call to setToolbarHidden:animated: in the viewWillAppear: method does not always give a smooth animation with no white rectangle artifacts.

What does always work is to put the setToolbarHidden:animated: call in the viewDidAppear: method. This means that the toolbar hiding animation is triggered after the navigation controller has finished pushing the new view onto the stack, so no white rectangles. However, it also means that the whole animation is in two stages: the first animates the view in, the second hides the toolbar, so you have the appearance of a "delayed" toolbar hide. I acknowledge that this isn't always what you want.

Ian Bourke