当用户单击地图时,我想在我的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.