MKAnnotationView 上的 UILongPressGestureRecognizer 不适用于单点触摸

发布于 2024-12-13 17:49:14 字数 719 浏览 4 评论 0原文

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

是什么阻止手势识别器仅通过一次触摸就被触发?

实现

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

普通 UIView 中的相同实现显示了一键式操作的预期行为。然而,可以使用 touchesBegan:touchesEnded: 来获得长按手势,我仍然很好奇这是什么原因。

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?

Implementation

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花间憩 2024-12-20 17:49:14

您见过这个问题吗?

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

[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];

Have you seen this question ?

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文