如果一張圖片既要單擊手勢闷游, 又要雙擊手勢掸屡,要怎么處理原在,看完這句代碼你就知道了
UITapGestureRecognizer*doubleRecognizer = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(handleDoubleTapGesture:)];
doubleRecognizer.numberOfTapsRequired=2;
[_containerViewaddGestureRecognizer:doubleRecognizer];
UITapGestureRecognizer*singleRecognizer = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(handleTapGesture:)];
[_containerViewaddGestureRecognizer:singleRecognizer];
[singleRecognizerrequireGestureRecognizerToFail:doubleRecognizer];
單擊事件的執(zhí)行依賴于雙擊事件失敗的基礎(chǔ)上那先,如果不加這句依賴關(guān)系栖雾,雙擊兩次的時(shí)候,只會執(zhí)行兩次單擊事件瓢湃,永遠(yuǎn)不會執(zhí)行雙擊事件理张。這個(gè)依賴關(guān)系只適用于同一個(gè)控制器,若是在不同的控制器绵患,可使用下面的代理設(shè)置優(yōu)先級
- (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer*)otherGestureRecognizer
{
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer*)otherGestureRecognizer
{
}