Prevent the animation when clicking "Back" button in a navigation bar?

Dirty Henry picture Dirty Henry · Jun 25, 2010 · Viewed 19.8k times · Source

My application has a navigation controller and I don't want any animation in it :

  • to prevent an animation when pushing a view, it's easy, via the pushViewController:animated: method

  • but when I click the "back" button on this subview, there's an animation ! KO ! What can I do to prevent this animation ?

Answer

Evgeny Karpov picture Evgeny Karpov · Jun 17, 2016

This prevents default animation.

- (void)viewWillDisappear:(BOOL)animated {
    [UIView setAnimationsEnabled: NO];
}

- (void)viewDidDisappear:(BOOL)animated {
    [UIView setAnimationsEnabled: YES];
}

In case if you need a custom animation

- (void)viewWillDisappear:(BOOL)animated {
    [UIView setAnimationsEnabled: NO];

    CATransition *transition = [CATransition animation];
    transition.duration = 0.3;
    transition.type = kCATransitionFade;
    [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
}

- (void)viewDidDisappear:(BOOL)animated {
    [UIView setAnimationsEnabled: YES];
}