1
votes

I'd like to code my own tap gesture recognizer, to detect the number of taps and number of touches (I don't want to use the iOS tap gesture recognizer because I want to extend it later in various other manners) ;

I tried the following : use the first motionBegin number of touches as the numberOfTouches of the tap, increment the numberOfTaps, and start the tap detection timer to detect the tap gesture if no new taps has been seen in a while

The problem is that one quickly realises that when doing a double-touch tap gesture, iOS either correctly detects one motionBegin with a double touch, or two quick one touch events. I guess a correct implementation should try to detect those quick one touch events that happen closely, but I'm wondering if there is a better way to implement the gesture recognizer.

Someone knows how the iOS tap gesture is implemented?

1
Ditto above @hpiOSCoder comment if you want serious help from the community. Regarding this question - just subclass UIGestureRecognizer - its designed for that. Why on earth would you start from scratch? Subclass it or the UITapGestureRecognizer.David H

1 Answers

0
votes
1. Add UIGestureRecognizerDelegate in your .h file. like
@interface finalScreenViewController : UIViewController <UIGestureRecognizerDelegate>
{
// do your stuff
}


2. Create a view in your viewDidLoad method (or any other method) you wanna to add the gesture in your .m file
ex 

UIView * myView=[[UIView alloc]init];
myView.frame=CGRectMake(0,0.self.view.frame.size.width,self.view.frame.size.height);
[self.view addSubView: myView];



UITapGestureRecognizer *letterTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapMethod:)];
        letterTapRecognizer.numberOfTapsRequired = 1;
        [myView addGestureRecognizer:letterTapRecognizer];



3. you can get view by

- (void) tapMethod:(UITapGestureRecognizer*)sender {
     UIView *view = sender.view; 
     NSLog(@"%d", view.tag);//By tag, you can find out where you had tapped. 
}