简体   繁体   English

在自定义MKAnnotationView中使用UILongPressGestureRecognizer遇到麻烦

[英]Trouble using UILongPressGestureRecognizer in custom MKAnnotationView

Having trouble with a UILongPressGestureRecognizer in a custom subclass of MKAnnotationView. 在MKAnnotationView的自定义子类中使用UILongPressGestureRecognizer遇到麻烦。 The callback is fired only intermittently. 回调仅间歇地触发。 If I make the minimumPressDuration shorter, it fires more frequently. 如果我使minimumPressDuration变短,它会更频繁地触发。 With a minimumPressDuration value of 0.1, it fires every time. 最小PressDuration值为0.1时,它将每次触发。 With a value of 0.4, it never fires at all, no matter how long I leave my finger on it. 值为0.4时,无论我将手指放在上面多长时间,它都不会触发。 At 0.2 it is hit or miss. 值为0.2时命中或未命中。

If I use a Tap gesture (as below), it works fine. 如果我使用“点击”手势(如下所示),则效果很好。 I'm using LongPress gestures on other views and they work fine. 我在其他视图上使用LongPress手势,它们工作正常。 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). 我只是在MKAnnotationView上遇到了这个问题,所以我想知道AnnotationViews上的其他一些内部事件回调是否会干扰(调出等)。

I see this problem on iOS4 (sim and phone) and 3.2 (sim, don't have a device). 我在iOS4(SIM卡和手机)和3.2(SIM卡,没有设备)上看到了此问题。

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? 任何iPhone专家都知道为什么会发生这种情况?

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. 据我所知,3.2和iOS 4中的标记已经附加了长按手势以处理标记拖动。 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 * 这只是一个猜测*

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM