3

I have the following problem: I have overridden popViewControllerAnimated:(BOOL)animated of UINavigationController because I would like to have a custom animation. The code is as follows:

- (UIViewController *)popViewControllerAnimated:(BOOL)animated 
{
    UIViewController *poppedCtrl = [super popViewControllerAnimated:NO];
    [((customViewController *) self.topViewController) doCustomAnimation];
    return poppedCtrl;
}

Unfortunately the UINavigationBar seems to ignore that I explicitly disable the built in animation and it is still animated.

What do I have to do to also prevent the animation of the navigation bar?

Marcus Leon
  • 55,199
  • 118
  • 297
  • 429
zlajo
  • 2,173
  • 1
  • 19
  • 25

2 Answers2

11

After some reading and also some experimentation I finally found out what needs to be done to achieve the desired behavior.

To prevent the navigation bar from being animated it is not sufficient to override (UIViewController *)popViewControllerAnimated:(BOOL)animated.

It is also necessary to create a custom navigation bar and override (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated:

- (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated {
    return [super popNavigationItemAnimated:NO];
}

Of course this custom navigation bar must also be the one which is used (I just replaced the navigation bar which is used by my navigation controller in the interface builder).

Marcus Leon
  • 55,199
  • 118
  • 297
  • 429
zlajo
  • 2,173
  • 1
  • 19
  • 25
  • 3
    any reason why this behaviour doesn't also work for pushNavigationItem: ... ? – horseshoe7 Jan 22 '14 at 15:59
  • Nice work! I noticed that the back button still fades out in iOS 7 - any thoughts on how to transition instantly? – N V Mar 06 '14 at 23:38
1

If anyones looking to disable push animation - this works for me, by overrideing this method on UINavigationBar:

- (void)pushNavigationItem:(UINavigationItem *)item {
    NSMutableArray* items = [[self items] mutableCopy];
    [items addObject:item];
    self.items = items;
}
Cherpak Evgeny
  • 2,659
  • 22
  • 29