Insert this line before adding shortPressGesture:
[shortPressGesture requireGestureRecognizerToFail:longPressGesture]
Note: shortGesture will not be called immediately after a 0.3 second hold, but when the rollback is released if it ranged from 0.3 second to 1.2 second. If the crane is longer than 1.2 s (you have 1.5 s in your code, which is probably a typo), then only longPressGesture will start.
EDIT:
However, if you want event handlers to fire (in the case of a long press), you must do this:
Your UIView
should implement the <UIGestureRecognizerDelegate>
file in .h
.
In the .m
file, you add this method:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES; }
Now instead of adding a line:
[shortPressGesture requireGestureRecognizerToFail:longPressGesture]
You add two lines:
shortPressGesture.delegate = self; longPressGesture.delegate = self;
NOTE. If you have another UIGestureRecognisers
associated with your UIView
, you will need to add some validation to shouldRecognizeSimultaneouslyWithGestureRecognizer:
otherwise you can just return YES
.
source share