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

标签 ios cocoa-touch mkmapview uigesturerecognizer mkannotationview

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

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

实现

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

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

最佳答案

你见过这个question

为了使用我的 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];

关于ios - MKAnnotationView 上的 UILongPressGestureRecognizer 不适用于单点触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8021019/

相关文章:

ios - UILabel 无法正确更新

ios - 在 animateAlongsideTransition block 内的 UIImage 上进行交叉溶解

ios - 如何绘制(_ rect : CGRect) actually work?

iphone - 从 xib 中提取 UI 项目?

objective-c - UITextField "value changed"字段更新时未触发

ios - 创建一个特定大小的空文件并使用 fseek 将新数据写入特定位置

ios - 从服务器获取 JSON 后如何更新应用程序中的标签?如果应该实时更新

ios - MKMapView 有时会缩放到用户位置有时会缩放到不知名的地方

ios - 当我搜索一个地方时,它会掉落一个 pin mapView

ios - 从 MKMapView 中仅移除餐厅