如果一张图片既要单击手势, 又要双击手势,要怎么处理,看完这句代码你就知道了
UITapGestureRecognizer*doubleRecognizer = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(handleDoubleTapGesture:)];
doubleRecognizer.numberOfTapsRequired=2;
[_containerViewaddGestureRecognizer:doubleRecognizer];
UITapGestureRecognizer*singleRecognizer = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(handleTapGesture:)];
[_containerViewaddGestureRecognizer:singleRecognizer];
[singleRecognizerrequireGestureRecognizerToFail:doubleRecognizer];
单击事件的执行依赖于双击事件失败的基础上,如果不加这句依赖关系,双击两次的时候,只会执行两次单击事件,永远不会执行双击事件。这个依赖关系只适用于同一个控制器,若是在不同的控制器,可使用下面的代理设置优先级
- (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer*)otherGestureRecognizer
{
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer*)otherGestureRecognizer
{
}