我一直在尝试在 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/