双击注释视图
Double tap on annotation view
好的,情况:
我有注释标记,当我点击其中一个时,它会调用方法
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MYCustomAnnotationView *)view
然后我从 (MYCustomAnnotationView *)view 中获取一些 属性 的值,并根据它们进行一些移动。
只有双击注释时我才需要做这个动作。
我做了什么:
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 这样的东西。也许有人知道在这种情况下有什么帮助?
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。
好的,情况:
我有注释标记,当我点击其中一个时,它会调用方法
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MYCustomAnnotationView *)view
然后我从 (MYCustomAnnotationView *)view 中获取一些 属性 的值,并根据它们进行一些移动。
只有双击注释时我才需要做这个动作。
我做了什么:
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 这样的东西。也许有人知道在这种情况下有什么帮助?
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。