ios – 单击MKMapView而不会破坏双击缩放

当用户单击地图时,我想在我的MKMapView上放一个图钉.我有pin码工作,我有单击工作,但当我双击缩放我先点击一下.这是我的代码来设置识别器:
self.doubleTap = [[UITapGestureRecognizer alloc]
                      initWithTarget:self action:@selector(handleDoubleTap:)];
    self.doubleTap.numberOfTapsRequired = 2;
    self.doubleTap.numberOfTouchesRequired = 1;
    [mapView_ addGestureRecognizer:doubleTap_];

    self.singleTap = [[UITapGestureRecognizer alloc]
                      initWithTarget:self action:@selector(handleGesture:)];
    self.singleTap.numberOfTapsRequired = 1;
    self.singleTap.numberOfTouchesRequired = 1;
    [self.singleTap requireGestureRecognizerToFail: doubleTap_];
    [mapView_ addGestureRecognizer:singleTap_];

现在,这引起苹果公司的注意并不奇怪:

Note: In the case of the single-tap versus double-tap gestures,if a
single-tap gesture recognizer doesn’t require the double-tap
recognizer to fail,you should expect to receive your single-tap
actions before your double-tap actions,even in the case of a double
tap. This is expected and desirable behavior because the best user
experience generally involves stackable actions.

所以我将requireGestureRecognizerToFail添加到我的单击识别器中.

[singleTap requireGestureRecognizerToFail: doubleTap];

这确保我的单击识别器不会获得双击.

但…

现在我的双击识别器获得了双击,MKMapView无法获得它们.我已经尝试在识别器中将cancelsTouchesInView设置为NO,但这也没有帮助.

所以我需要一种方法来阻止我的单击识别器获得双击(这似乎不太可能)或者让我的双击事件到我的mapView.

解决方法

发布的代码似乎在iOS 6中正常工作.
双击由地图视图自动处理,不会干扰单击.

在iOS 5.x中,要使地图视图执行其正常的双击处理而不干扰您的单击,请实现shouldRecognizeSimultaneouslyWithGestureRecognizer委托方法并从中返回YES(需要设置双击手势的委托属性)仅识别器).

不确定为什么在iOS 6中没有必要这样做.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...