views:

343

answers:

1

I'm trying to add a pin (MKAnnotation and MKAnnotationView) to my MKMapView and allow the user to drag it around.

I'd also like to make the dragging of the pin animated and interactive like the iPhone's Map App.

My question is how do I change the state of the MKAnnoationView so that it's hovering over the map (so the pin isn't actually inside the map)?

I'm not 100% sure how to do this.

At present, my colleague as found an hovering image that he swaps with the default MKAnnotationView, but that means I can't easily animate between the two.

A: 

Not sure what you exactly want to do but I have used Apple's example in the iPhone App Programming Guide (Handling Events in an Annotation View) to implement the draggable pin.

It has a partial code but tha may be enough for you to figure it out.

Basically, you must subclass the MKAnnnotation and MKPinAnnotationView and in your CustomAnnotationView class you have to implement delegate methods to handle touch events, as shown in the Apple example.

There was a bit of filling out or modification needed because the code snippet was not complete, but I have reproduced the behaviour of the pin on the Apple's iPhone Map app exactly (except that I did not implement the right accessory button).

In it, the pin feels like it is hovering. So, I suspect that you have no need for the hovering image you have mentioned.

I also presume that by providing a BOOL property, you could make the pin draggable or "fixed" programmatically.

Does this help?

Yoichi