ryan
ryan

Reputation: 5099

Animation issue when hiding iPhone toolbar

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?

Upvotes: 0

Views: 2280

Answers (5)

asilva
asilva

Reputation: 16

I have found very useful to set the hidesBottomBarWhenPushed property in the init of your view controller.

For instance:

- (id)init
{
    self = [super initWithStyle:UITableViewStyleGrouped];
    if (self) {
        // Custom initialization
        self.navigationItem.rightBarButtonItem = self.editButtonItem;
        self.hidesBottomBarWhenPushed = YES;
    }
    return self;
}

It hides those spurious toolbars that appear in the push and pop transitions. Also, it frees you from manually hiding the toolbar in the ViewWillAppear method or similar approaches.

Upvotes: 0

Webber Lai
Webber Lai

Reputation: 2022

TRY THIS

- (IBAction)hideTheToolBar:(id)sender{
    //[toolBar setHidden:YES];
    if (toolBar.hidden == NO)
    {
        [UIView animateWithDuration:0.25 delay:0.0
                            options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction
                         animations:^(void)
         {
             toolBar.alpha = 0.0f;
         }
                         completion:^(BOOL finished)
         {
             toolBar.hidden = YES;
         }
         ];
    }
}

Upvotes: 1

user309150
user309150

Reputation:

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.

Upvotes: 1

mvl
mvl

Reputation: 789

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

Upvotes: 0

Jeff Kelley
Jeff Kelley

Reputation: 19071

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

Upvotes: 1

Related Questions