UITouch

Let’s have a look at touchesBegan. When touchesBegan is called, it returns an event. We can call allTouches to get the touches and then locate the first touch. Each touch has many properties, including tapCount, timeStamp and the view it was contained in. We can manipulate these to create whatever desired action we want.

Touches
-(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event { NSSet *allTouches = [event allTouches];
//first touch
UITouch *touch = [[allTouches allObjects] objectAtIndex:0];


Understanding each touch
tapCount
timeStamp
view


Gesture Recognizers
If you want to detect gestures, there’s an app for that. But you have to build it. However, Apple has created recognizers called UIGestureRecognizers which save lives. You can easily detect motions and gestures such as tapping, pinching, panning, swiping, rotating, and long presses. They are extremely easy to add and customize, and include delegates for further customization.

UIGestureRecognizer
UITapGestureRecognizer *doubleFingerDTap =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleDoubleTap:)];

Add to view
[self.view add doubleFingerDTap];

Let’s look at how we can use them. First we create the UIGestureRecognizer, in this case, we use a UITapGestureRecognizer.
We add it to the view, and implement the delegate if we want. Now, the delegate has important methods such as requiring other gesture recognizers to fail. For instance, if you have a singleTapGestureRecognizer and a doubleTapGestureRecognizer, you would need the double tap gesture to fail before recognizing the single tap. That means, you will have to wait for a few seconds to confirm that it is not a double tap, before performing the single tap action.