ios learner
ios learner

Reputation: 317

navigationController:animationControllerForOperation:fromViewController:toViewController: not called

I have a very weird problem, in a typical animated transition code like below, after do the transition a few time then the view becomes irresponsive. I dug a little bit and found that the navigationController:animationControllerForOperation:fromViewController:toViewController: method is not called, even the pushViewController:animated: method is called. Any ideas?

This VC transits to another VC, then that VC can transit back with an interactive animated transition. The same problem happens in the other view as well, i.e., the transition is initiated but navigationController:animationControllerForOperation:fromViewController:toViewController: is not called. This only happens after I played with the app for like half a minute.

.h file 
@interface ViewController : UIViewController <UINavigationControllerDelegate>

@end

.m file
@implementation ViewController

- (void)viewDidAppear:(BOOL)animated
{
    [self.navigationController setDelegate:self];
}

- (void) transit_to_next_view
{
    //...
    UIViewController* newvc;
    [self.navigationController pushViewController:newvc animated:YES];
}

// animated transition
- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC
{
     // return animator 
}
@end

Upvotes: 1

Views: 2666

Answers (1)

ios learner
ios learner

Reputation: 317

it turns out that I mistakenly added an pan recognizer to the navigationController in the toViewController's viewDidLoad function. Even if the transition is canceled, the pan recognizer is still alive and will route all pan gestures to the canceled toViewController instead of the visible fromViewController. So the pan recognizer in the fromViewController is not fired and the transition never happen again. Moving the pan recognizer adding from the toViewController's viewDidLoad function to its viewDidAppear function fixed the problem.

Upvotes: 1

Related Questions