I am using a custom Left Menu Controller which can be opened by UIPanGestureRecognizer
when the UINavigationController
is only at it's Top-Level. If some UIViewController
is pushed onto the stack, I want the interactivePopGestureRecognizer
to work as expected and pop the VC when user swipes from left-to-right instead of the Left-Menu being opened.
To achieve this, i sub-classed the UINavigationController
as follows:
- (void)viewDidLoad {
[super viewDidLoad];
//[self.interactivePopGestureRecognizer setDelegate:nil];
[self.view addGestureRecognizer:[self createPanGestureRecognizer]];
}
- (UIPanGestureRecognizer *) createPanGestureRecognizer {
SGFPanGestureRecognizer * panRecognizer = [[SGFPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureRecognized:)];
return panRecognizer;
}
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
if(self.viewControllers.count == 1)
if(self.view.gestureRecognizers && self.view.gestureRecognizers.count>0)
for (UIGestureRecognizer * recog in self.view.gestureRecognizers)
{
if([recog isKindOfClass:[SGFPanGestureRecognizer class]]) {
[self.view removeGestureRecognizer:recog];
break;
}
}
[super pushViewController:viewController animated:animated];
}
-(UIViewController *)popViewControllerAnimated:(BOOL)animated {
UIViewController * vc = [super popViewControllerAnimated:animated];
if(self.viewControllers.count == 1)
[self.view addGestureRecognizer:[self createPanGestureRecognizer]];
return vc;
}
Everything is working fine except one: When i am at a detailViewController and I swipe from left, the VC starts the "POP" animation which goes along my finger. If I leave the gesture too quick, the detailViewController doesn't really gets popped and rolls back the popping animation. However, this action fires the popViewControllerAnimated
and my logic above becomes useless.
SUMMARY:
So is there a way to understand if the swipe-to-back gesture is released too early to really pop the UINavigationController
?