Trouble using UILongPressGestureRecognizer in custom MKAnnotationView

点点圈 提交于 2019-12-11 13:04:26

问题


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?


回答1:


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 *


来源:https://stackoverflow.com/questions/3714174/trouble-using-uilongpressgesturerecognizer-in-custom-mkannotationview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!