Jacob
Jacob

Reputation: 25

UITapGestureRecognizer is not firing

Why is swipeRightL firing events and tapR is not?

UISwipeGestureRecognizer *swipeRightL=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeLeft)];
swipeRightL.numberOfTouchesRequired=1;
swipeRightL.direction=UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeRightR];
[self.view addGestureRecognizer:swipeRightL];
UITapGestureRecognizer *tapR=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onTap)];
tapR.numberOfTapsRequired=1;
tapR.numberOfTouchesRequired=1;
[self.view addGestureRecognizer:tapR];

Upvotes: 0

Views: 313

Answers (3)

Jack Freeman
Jack Freeman

Reputation: 1414

It's likely your gestures are conflicting with one another. If you remove the swipe gesture does it work then?

You probably want to look at this delegate callback and return YES:

– gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:

Upvotes: 1

iiFreeman
iiFreeman

Reputation: 5175

remove setups like:

tapR.numberOfTaps/Touches it's already 1 by default.

Try to implement delegate methods and check did they fired?

tapR.delegate = self;

- (BOOL)gestureRecognizerShouldBegin:sender { return YES; }

Also can you provide some details about views structure? For example, some another gestures (in scroll view or something) can be a reason why your swipe not firing.

Upvotes: 0

GoZoner
GoZoner

Reputation: 70135

The Apple example code of "Simple Gesture Recognizers" prodives examples of tap, swipe and rotate gesture recognizers with all three types working within one view. Check it out. The example code uses storyboards to fully configure the view and its controller so the code is a bit sparse. But you should be able to compare your coded configuration with the Xcode 'Attributes Inspector' and the 'Connections Inspector' to identify your differences.

Upvotes: 0

Related Questions