I have a UIImageView with a UILongPressGestureRecognizer attached that never seems to detect a long press gesture no matter how I configure the gesture recognizer. However, if I swap it out for a UITapGestureRecognizer, that works just fine. What could possibly be going on?
This is how I’m configuring my UILongPressGestureRecognizer:
UIImageView* cellView = (UIImageView*)[view viewWithTag:5];
UILongPressGestureRecognizer* longPressGestureRec =
[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(cellLongPress:)];
longPressGestureRec.numberOfTapsRequired = 1;
longPressGestureRec.numberOfTouchesRequired = 1;
longPressGestureRec.minimumPressDuration = 0.4;
[cellView addGestureRecognizer:longPressGestureRec];
[longPressGestureRec release];
This is what cellLongPress looks like:
-(void)cellLongPress:(UILongPressGestureRecognizer*)recognizer
{
// This never gets called.
NSLog(@"someone long pressed me");
}
Pretty straightforward, right? No luck so far getting it to work, though. Any ideas?
The
numberOfTapsRequiredis set to1which means the user has to tap once before starting the long press (finger down, finger up, finger down for 0.4 seconds, gesture recognized).Change
numberOfTapsRequiredto0(which is the default).For that property, the documentation just says:
But in the comments in
UILongPressGestureRecognizer.h, it says: