UILongPressGestureRecognizer on MKAnnotationView not working for single touch

懵懂的女人 提交于 2020-01-02 10:23:15

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/8021019/uilongpressgesturerecognizer-on-mkannotationview-not-working-for-single-touch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!