iOS interactivePopGestureRecognizer enables itself after ViewController is pushed

273 Views Asked by At

I have a subclass of UINavigationController that has maximum of 4 ViewControllers in the stack. Lets call them firstVC ... fourthVC. My NavController can perform custom transitions between VCs and ios7/8 back gesture is supposed to be disabled and enabled depending on which VC is currently at the top of the stack. I've set my root VC (firstVC) as a NavController's delegate and trying to enable/disable back gesture in the delegate's method

-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {

    if ([viewController respondsToSelector:@selector(needsBackGestureEnabled)]) {

        [self.navigationController.interactivePopGestureRecognizer setEnabled:YES];
        NSLog(@"Back gesture enabled");
        self.navigationController.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)self;

    } else {

        if ([navigationController.interactivePopGestureRecognizer isEnabled]) {
            [self.navigationController.interactivePopGestureRecognizer setEnabled:NO];
            NSLog(@"Back gesture disabled");
            self.navigationController.interactivePopGestureRecognizer.delegate = nil;
        }
    }

}

It works like a charm except one glitch. I feel like a short scheme might explain situation better:

FirstVC -[CustomTran]-> SecondVC -[push]-> ThirdVC -[push]-> FourthVC

FourthVC is the only one that have -needsBackGestureEnabled selector, but after transition from second to third back gesture gets enabled by itself. Even though the back button is susbtituted with the CustomBarButtonItem. I feel like performing default -pushViewController animation makes back gesture enabled somehow. I tried to ecplicitly disable it in my NavController subclass in -pushViewController but it didn't change a thing. Any idea why this is happening and how to fix this?

0

There are 0 best solutions below