rptwsthi
rptwsthi

Reputation: 10182

HowTo detect tap on map annotaition Pin?

I want to detect tap on annotation pin(of mapkit) so that I can perform action on that event.

Now the default annotation flag pops up in case I touch the annotation pin. I want to customise that to call my method when pin is touched.

Upvotes: 3

Views: 3630

Answers (2)

Nitish
Nitish

Reputation: 14123


You need to implement the following delegate method

 (MKAnnotationView) mapView viewForAnnotation:(id) annotation  

Then just declare following in this method

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

Then you can add UI to your callout eg UIButton or UIImage as view.rightCalloutAccesoryView View.leftCalloutAccesoryView

Upvotes: 7

Ravin
Ravin

Reputation: 8564

As pin on map is MKAnnotationView you can add UITapGestureRecognizer on it(of yours), but if it already has some GestureRecognizer than you will need to remove it first.

Thanks

Upvotes: -1

Related Questions