首页 > 代码库 > 两个滑动手势冲突处理

两个滑动手势冲突处理

手势的话,有一个可以解决这个问题的API方法,如果otherGestureRecognizer这个手势没有执行成功的话,才会执行调用这个方法的手势。

- (void)requireGestureRecognizerToFail:(UIGestureRecognizer *)otherGestureRecognizer


- (UIScreenEdgePanGestureRecognizer *)screenEdgePanGestureRecognizer//获取边缘返回手势{    UIScreenEdgePanGestureRecognizer *screenEdgePanGestureRecognizer = nil;    if (self.navigationController.view.gestureRecognizers.count > 0) {        for (UIGestureRecognizer *recognizer in self.navigationController.view.gestureRecognizers){            if ([recognizer isKindOfClass:[UIScreenEdgePanGestureRecognizer class]]) {                screenEdgePanGestureRecognizer = (UIScreenEdgePanGestureRecognizer *)recognizer;                break;            }        }    }    return screenEdgePanGestureRecognizer;}
我们在操作滚动视图的时候的,只要滚动视图的手势能够触发,就不会执行滑动返回的那个手势,并且除了这个滚动视图外,在其他地方对滑动返回没有影响。
[[self screenEdgePanGestureRecognizer] requireGestureRecognizerToFail:self.scrollView.panGestureRecognizer];
 

两个滑动手势冲突处理