在iOS的手势识别中,有时我们要用手势实现页面pop(比如微信的左滑返回),实现时UIGestureRecognizerDelegate,会有这么一个(可选的)方法:
// called when a gesture recognizer attempts to transition out of UIGestureRecognizerStatePossible. returning NO causes it to transition to UIGestureRecognizerStateFailed
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer;
实现它有一些常见的处理,比如:
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { // Don't handle gestures if navigation controller is still animating a transition if ([self.navigationController.transitionCoordinator isAnimated]) return NO; if (self.navigationController.viewControllers.count < 2) return NO; return YES; }
解释一下,第一个是说如果仍然在transaction的动画中,不识别,第二个是说如果小于2个不识别(因为没的可pop了)。
顺便说一下,这个左滑pop的手势是iOS的navigationController自带的:
self.navigationController.interactivePopGestureRecognizer.delegate = self; self.navigationController.interactivePopGestureRecognizer.enabled = YES;