Requiring Gesture Recognizer Failures

In some cases, a gesture recognizer needs to fail in order to meet an app’s requirements. A great example is when a tap and a double tap need to work on the same view. By default, if a single-tap gesture recognizer and a double-tap gesture recognizer are attached to the same view, the single-tap recognizer will fire even if a double tap occurs—so both the single-tap and the double-tap target methods will get called. To see this in action, comment out the initial tap recognizer in viewDidLoad in the sample project.

/*UITapGestureRecognizer *tapRecognizer =[[UITapGestureRecognizer alloc] initWithTarget:selfaction:@selector(myGestureViewTapped:)];[myGestureView addGestureRecognizer:tapRecognizer]; ...

Get iOS Components and Frameworks: Understanding the Advanced Features of the iOS SDK now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.