View上的UILongPressGestureRecogniz

View上的UILongPressGestureRecogniz

本文介绍了MKAnnotationView上的UILongPressGestureRecognizer不适用于单点触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图在MKAnnotationView子类中使用UILongPressGestureRecognizer.有趣的是,手势识别器仅在使用两个矿石手指/触摸时才触发.

I've been trying to use a UILongPressGestureRecognizer in a MKAnnotationView subclass. Interestingly the gesture recognizer only triggers when using two ore fingers/touches.

是什么导致手势识别器仅需轻触一次即可触发?

What prevents the gesture recognizer to get triggered with only one touch?

实施

UILongPressGestureRecognizer *pressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self
                                                                                                      action:@selector(handleLongPress:)];
pressRecognizer.minimumPressDuration = 0.25;
pressRecognizer.numberOfTapsRequired = 0;
pressRecognizer.numberOfTouchesRequired = 1;

正常UIView中的相同实现显示了一次触摸即可实现的预期行为.但是可以使用touchesBegan:touchesEnded:来获得长按手势,但我仍然很好奇这是什么原因.

The same implementation in a normal UIView shows the expected behaviour working with one touch. Yet it's possible to use touchesBegan: and touchesEnded: to get a long press gesture working I'm still curious what the reason for this is.

推荐答案

您是否看到过问题?

要使用我的UILongPressGestureRecognizer,我禁用了AnnotationView并向其中添加了GestureRecognizer:

For using my UILongPressGestureRecognizer I disabled AnnotationView and added GestureRecognizer to it:

[ann_view setEnabled:NO];
UILongPressGestureRecognizer* long_press = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAnnotationView:)];
long_press.minimumPressDuration = 1.5;
[ann_view addGestureRecognizer:long_press];
[long_press release];

这篇关于MKAnnotationView上的UILongPressGestureRecognizer不适用于单点触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 10:39