Having trouble with a UILongPressGestureRecognizer in a custom subclass of MKAnnotationView. The callback is fired only intermittently. If I make the minimumPressDuration shorter, it fires more frequently. With a minimumPressDuration value of 0.1, it fires every time. With a value of 0.4, it never fires at all, no matter how long I leave my finger on it. At 0.2 it is hit or miss.
If I use a Tap gesture (as below), it works fine. I'm using LongPress gestures on other views and they work fine. It's just on the MKAnnotationView that I have this problem, so I'm wondering if some of the other internal event callbacks on AnnotationViews are interfering (callout, etc).
I see this problem on iOS4 (sim and phone) and 3.2 (sim, don't have a device).
Here is how I'm creating the gesture recognizer:
#define USE_LONG_PRESS 1
#define USE_TAP 0
#if USE_LONG_PRESS
UILongPressGestureRecognizer *longPressGR =
[[UILongPressGestureRecognizer alloc] initWithTarget:self
action:@selector(handleLongPress:)];
longPressGR.minimumPressDuration = 0.2;
[self addGestureRecognizer:longPressGR];
[longPressGR release];
#endif
#if USE_TAP
UITapGestureRecognizer *tapGR =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleTap:)];
[self addGestureRecognizer:tapGR];
[tapGR release];
#endif
And the callback methods are defined in this class as follows:
- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer {
NSLog(@"LONG PRESS");
}
- (void)handleTap:(UIGestureRecognizer *)gestureRecognizer {
NSLog(@"TAP");
}
Any iPhone gurus have any idea why this might be happening?