在自定义 MKAnnotationView 中使用 UILongPressGestureRecognizer 时遇到问题 [英] Trouble using UILongPressGestureRecognizer in custom MKAnnotationView
问题描述
在 MKAnnotationView 的自定义子类中使用 UILongPressGestureRecognizer 时遇到问题.回调只会间歇性地触发.如果我使 minimumPressDuration 更短,它会更频繁地触发.当 minimumPressDuration 值为 0.1 时,它每次都会触发.值为 0.4 时,无论我将手指放在上面多久,它都不会触发.在 0.2 时命中或未命中.
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.
如果我使用 Tap 手势(如下所示),它工作正常.我在其他视图上使用 LongPress 手势,它们工作正常.我只是在 MKAnnotationView 上遇到了这个问题,所以我想知道 AnnotationViews 上的其他一些内部事件回调是否有干扰(标注等).
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).
我在 iOS4(sim 和手机)和 3.2(sim,没有设备)上看到这个问题.
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");
}
任何 iPhone 专家都知道为什么会发生这种情况?
Any iPhone gurus have any idea why this might be happening?
推荐答案
据我所知,3.2 和 iOS 4 中的标记已经附加了一个长按手势来处理标记拖动.难道这会干扰您的长按手势识别器?也许这就是为什么较短的持续时间起作用的原因;它在内置的长按识别器可以之前捕获手势.
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.
- 这只是猜测*
这篇关于在自定义 MKAnnotationView 中使用 UILongPressGestureRecognizer 时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!