Reputation: 9700
I've attached a UITapGestureRecognizer
to a UIView
in my application. If the user double-taps it, the buttons inside that view get randomly re-arranged. Working fine, lovely.
However, the user can also trigger this by double-tapping one of the buttons themselves, or even by tapping two buttons on different parts of the screen.
Is there a sensible / easy way to have this double-tap only work if the two taps are within x
number of pixels, and on the view itself, not any elements within it such as these UIButton
s?
Upvotes: 2
Views: 648
Reputation: 3001
I think the usual way to do this is with shouldReceiveTouch
. Check out this question for a lengthy discussion and all the details.
Upvotes: 1
Reputation: 104082
One way to do this would be to attach a single tap gesture recognizer to the buttons -- this will preempt the button's normal touch events, so you would have to put the button's action method in the gesture recognizer's action method. Then, you would add a dependency to the double tapper to have it only fire if the single tapper fails:
[self.doubleTapper requireGestureRecognizerToFail:self.tapper];
Upvotes: 0