(Rotate) iOS identifies click and double-click gestures with the same View

Requirements: Response to click and double-click methods on the same cell to enter different methods.

The problem with recognizing both click and double-click gestures in the view is that when a single-click operation is detected, there is no way to determine whether it is really a single-click operation or just the first click in a double-click operation.The solution to this problem is to wait a while for the second click when a click is detected, click if there is no second click, and double click if there is a second click.
There are two ways to detect gestures, one is to customize the subview, the override of event handling methods that the view inherits from the UIResponder class, touchesBegan:withEvent:and a series of other methods to detect gestures, the other is to use gesture recognizers, which are specific subclasses of UIGestureRecognize.

//Add bgView on the cell and two gesture detection methods to bgView     
bgView.userInteractionEnabled = YES;
UITapGestureRecognizer *singleTapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleSingleTap:)];
singleTapGesture.numberOfTapsRequired =1;
singleTapGesture.numberOfTouchesRequired  =1;
[bgView addGestureRecognizer:singleTapGesture];

UITapGestureRecognizer *doubleTapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleDoubleTap:)];
doubleTapGesture.numberOfTapsRequired =2;
doubleTapGesture.numberOfTouchesRequired =1;
[bgView addGestureRecognizer:doubleTapGesture];
//singleTapGesture can only start recognizing if the doubleTapGesture recognition fails (that is, it recognizes that it is not a double-click operation)          
[singleTapGesture requireGestureRecognizerToFail:doubleTapGesture];

//Method for responding to two gestures separately
-(void)handleSingleTap:(UIGestureRecognizer *)sender{
//chooseNum is the tag value of the view for the gesture response
   CGPoint touchPoint = [sender locationInView:self];

-(void)handleDoubleTap:(UIGestureRecognizer *)sender{
//chooseNum is the tag value of the cell for the gesture response
   UITableViewCell *v = (UITableViewCell *)[[sender view] superview];

Reference article address:
Author: Caterpillar Disaster
Links: https://www.jianshu.com/p/cdcde32cb252
Source: Short Book
The copyright in the brief book is owned by the author. For any form of reprinting, contact the author for authorization and indicate the source.

Posted on Sun, 12 Jan 2020 12:32:35 -0500 by jwaqa1