views:

86

answers:

1

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?

A: 

As far as I know the markers in 3.2 and iOS 4 already have a long press gesture attached to them to handle marker dragging. Could it be that that's interfering with your long press gesture recognizer? Maybe that's why a shorter duration works; it catches the gesture before the built in long press recognizer can.

  • this is just a guess *
nevan
Thanks -- that's a good point, but I thought the built in draggability was only added in iOS4? At least, the draggable property was only added then. Was there some other way to drag them in 3.2?
Chris