好的,有情况:
我有注释标记,当我点击其中一个时,它会调用方法
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MYCustomAnnotationView *)view
然后我从(MYCustomAnnotationView *)视图中获取一些属性的值,并依赖它们,做一些动作。
只有在双击注释时才需要进行此移动。
我做了什么:
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapOnAnnotationView)];
失败,因为我需要发送(MYCustomAnnotationView *)view
。我试图存储最后一次命中注释,但似乎没有正确的方法。
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] performSelector:@selector(doubleTapOnAnnotationView:mapView:) withObject:view withObject:mapView];
但它不起作用。
tapCount++;
switch (tapCount)
{
case 1: //single tap
[self performSelector:@selector(singleTap:) withObject: nil afterDelay: 0.2];
break;
case 2: //double tap
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(singleTap:) object:nil];
[self performSelector:@selector(doubleTap:) withObject: nil];
break;
default:
break;
}
if (tapCount>2) tapCount=0;
但它不适用于这种方法。
我认为我需要类似completionHandler的东西,当双击时。也许有人知道在这种情况下可以提供什么帮助?
答案 0 :(得分:0)
1)在-mapView viewForAnnotation
if ([annotationView gestureRecognizers] == nil) {
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapOnAnnotationView:)];
tapGesture.numberOfTapsRequired = 2;
[annotationView addGestureRecognizer:tapGesture];
}
2)
-(void)doubleTapOnAnnotationView:(UITapGestureRecognizer *)tap
{
MYCustomAnnotationView *view = (MYCustomAnnotationView*)tap.view;
...
}
感谢 Larme 。