Subclassing MKAnnotationView and overriding setDragState

后端 未结 3 1885
不知归路
不知归路 2020-12-01 11:25

This is about an iPhone App using MKMapKit:

I created a custom MKAnnotationView for a draggable Annotation. I want to create a custom animation. I set a custom pin i

3条回答
  •  情歌与酒
    2020-12-01 12:04

    While Brian's solution worked, it lacked taking into account the users finger blocking the annotation view which is being manipulated.

    This means that the user could not precisely place the pin once he was dragging it. The standard MKPinAnnotationView does a great job at this, what happens is when the finger begins dragging, the pin is lifted above the finger, and the visual point of the pin is used for placement not the previous centre point which now resides under the finger.

    In addition to this my implementation also adds another animation when dropping the pin after dragging, by lifting the pin and dropping it with a higher speed. This is very close the the native user experience and will be apreciated by your users.

    Please check out my gist on GitHub for the code.

    What's really cool is setting a delegate is optional, optionally a notification is sent when the annotation view is dropped back onto the map.

提交回复
热议问题