UITapGesture的单击和长按的手势同时识别区分

My solution was to not implement collectionView:didSelectItemAtIndexPath but to implement two gesture recognizers.

    self.doubleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(processDoubleTap:)];
    [_doubleTapGesture setNumberOfTapsRequired:2];
    [_doubleTapGesture setNumberOfTouchesRequired:1];   

    [self.view addGestureRecognizer:_doubleTapGesture];

    self.singleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(processSingleTap:)];
    [_singleTapGesture setNumberOfTapsRequired:1];
    [_singleTapGesture setNumberOfTouchesRequired:1];
    [_singleTapGesture requireGestureRecognizerToFail:_doubleTapGesture];

    [self.view addGestureRecognizer:_singleTapGesture];

This way I can handle single and double taps. The only gotcha I can see is that the cell is selected on doubleTaps but if this bothers you can you handle it in your two selectors.

The following line needs to be added:

doubleTapFolderGesture.delaysTouchesBegan = YES;

which eliminates interference with the single tap for cell selection. This provides a much more robust setup.

项目任务,要求同时实现点击和长按事件。

单击的效果可能更好,但是由于使用了第三方控件,不能实现单击

你可能感兴趣的:(gesture)