0
votes

I have problem with tap gesture. My case is: - A view with UITapGestureRecognizer to dismiss keyboard - A label on view, which has 2 gesture. One UITapGestureRecognizer to open popup, and UITapGestureRecognizer (number of touches is 2) to quickly confirm popup.

But when I tap on label, the UITapGestureRecognizer on view always receive the action. How can I forward action to UILabel.

Thanks

2

2 Answers

2
votes

To get taps on label, you need to enable user interaction for that label

To receive 2 taps you need to do following

In short [tap requireGestureRecognizerToFail:dTap]; will do trick for you making single tap to wait for a while to check if double tap is to happen

UITapGestureRecognizer *dTap = [[UITapGestureRecognizer alloc]
                                         initWithTarget:self 
                                         action:@selector(doubleTapped:)];
dTap.delegate = self;
dTap.numberOfTapsRequired = 2;
dTap.numberOfTouchesRequired = 1;
[label addGestureRecognizer:dTap];

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
                                   initWithTarget:self 
                                   action:@selector(tapped:)];
tap.delegate = self;
tap.numberOfTapsRequired = 1;
tap.numberOfTouchesRequired = 1;
[label addGestureRecognizer:tap];
[tap requireGestureRecognizerToFail:dTap];
1
votes

// it Enables user interaction on you Lable, by default its NO, so you have to do it.

[lbl setUserInteractionEnabled:YES];