我们有时候会遇到当两个手势(UIGestureRecognizer)放在不同view上,滑动公共区域时,只能响应上面view的手势。
那怎么修改它们的响应优先级或者同时让它们都响应呢?
1.修改响应优先级
UIGestureRecognizer类中有两个方法
//让自身这个手势事件响应优先级低于其它手势事件
//只是在对于比它响应优先级低的手势调用
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
//让自身这个手势事件响应优先级高于其它手势事件
//只是在对于比它响应优先级高的手势调用
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
还有一种是直接对两个手势
//让gestureTwo响应优先级低于gestureOne
[gestureTwo requireGestureRecognizerToFail:gestureOne];
2.同时响应
//共存 A手势或者B手势 代理方法里shouldRecognizeSimultaneouslyWithGestureRecognizer 有一个是返回YES,就能共存
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
最后时测试代码IOSStudyTest