Instance Method

setDragState(_:animated:)

Sets the current drag state for the annotation view.

Declaration

func setDragState(_ newDragState: MKAnnotationView.DragState, animated: Bool)

Parameters

newDragState

The new drag state for the annotation view.

animated

If true, the change to the new drag state should be animated; otherwise, it should be made without animations.

Discussion

Applications targeting iOS 4.2 and later can override this method and use it to implement drag support for custom annotation views. As the system detects user actions that would indicate a drag, it calls this method to update the drag state. In response to these changes, your custom implementation of this method should do the following:

The default implementation of this method sets the value of the dragState property to the value in the newDragState parameter only. Therefore, direct subclasses can simply call the inherited version of this method to change the drag state; otherwise, just change the value in the isDraggable property directly.

Changing the state to MKAnnotationView.DragState.dragging or MKAnnotationView.DragState.none is the way to signal to the map view that you are done with any animations you wanted to perform. For example, when a drag operation begins for a pin annotation, the MKPinAnnotationView class executes an animation to lift the pin off the map. Similarly, when the pin is dropped, the class performs a drop animation. Even if you do not perform any animations, you should call the inherited version of this method to update the dragState property.

You must not try to abort a new drag operation by changing the state from MKAnnotationView.DragState.starting to MKAnnotationView.DragState.none. If you do not want your annotation view to be draggable, set the isDraggable property to false.

See Also

Supporting Drag Operations

var isDraggable: Bool

A Boolean indicating whether the annotation view is draggable.

var dragState: MKAnnotationView.DragState

The current drag state of the annotation view.