如何检测点击地图注释Pin?

rpt*_*thi 3 iphone google-maps mapkit ios4

我想检测一下注释引脚(的mapkit),以便我可以对该事件执行操作.

现在,如果我触摸注释引脚,则会弹出默认注释标记.我想定制它来触摸引脚时调用我的方法.

Nit*_*ish 8


您需要实现以下委托方法

 (MKAnnotationView) mapView viewForAnnotation:(id) annotation  
Run Code Online (Sandbox Code Playgroud)

然后在这个方法中声明以下内容

MKPinAnnotationView *view=[[MKPinAnnotationView alloc]initWithAnnotation:annotation  reuseIdentifier:@"abc"];
view.canShowCallout=YES;
view.calloutOffset=CGPointMake(-20,10); //As per your choice
Run Code Online (Sandbox Code Playgroud)

然后你可以在你的标注中添加UI,例如UIButton或UIImage作为view.rightCalloutAccesoryView View.leftCalloutAccesoryView

  • ...当点击标注时,它将调用`mapView:annotationView:calloutAccessoryControlTapped:`委托方法(不需要addTarget或手势识别器). (3认同)
  • 如果你不想要标准的标注,你也可以使用`mapView:didSelectAnnotationView:`来检测tap. (2认同)