MGLAnnotationView

@interface MGLAnnotationView : UIView

The MGLAnnotationView class is responsible for representing point-based annotation markers as a view. Annotation views represent an annotation object, which is an object that corresponds to the MGLAnnotation protocol. When an annotation’s coordinate point is visible on the map view, the map view delegate is asked to provide a corresponding annotation view. If an annotation view is created with a reuse identifier, the map view may recycle the view when it goes offscreen.

  • Initializes and returns a new annotation view object.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithReuseIdentifier:
        (nullable NSString *)reuseIdentifier;

    Swift

    init!(reuseIdentifier: AnyObject!)

    Parameters

    reuseIdentifier

    The string that identifies that this annotation view is reusable.

    Return Value

    The initialized annotation view object.

  • This property will be set to the associated annotation when the view is visible.

    When the view is queued and waiting to be reused, the value will be set to nil.

    Declaration

    Objective-C

    @property (readonly, nonatomic, nullable) id<MGLAnnotation> annotation;
  • The string that identifies that this annotation view is reusable. (read-only)

    You specify the reuse identifier when you create the view. You use the identifier later to retrieve an annotation view that was created previously but which is currently unused because its annotation is not on screen.

    If you define distinctly different types of annotations (with distinctly different annotation views to go with them), you can differentiate between the annotation types by specifying different reuse identifiers for each one.

    Declaration

    Objective-C

    @property (readonly, nonatomic, nullable) NSString *reuseIdentifier;

    Swift

    var reuseIdentifier: UnsafeMutablePointer
  • Annotation view is centered at the coordinate point of the associated annotation.

    By changing this property you can reposition the view as needed. The offset is measured in points. Positive offset moves the annotation view towards the bottom right, while negative offset moves it towards the top left.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) CGVector centerOffset;

    Swift

    var centerOffset: Int32 { get set }
  • Setting this property to YES will force the annotation view to tilt according to the associated map view.

    Declaration

    Objective-C

    @property (getter=isFlat, assign, readwrite, nonatomic) BOOL flat;

    Swift

    var flat: Int32 { get set }
  • Defaults to NO and becomes YES when the view is tapped on.

    Selecting another view will first deselect the currently selected view. This property should not be changed directly.

    Declaration

    Objective-C

    @property (getter=isSelected, assign, readwrite, nonatomic) BOOL selected;

    Swift

    var selected: Int32 { get set }
  • Subclasses may override this method in order to customize appearance. This method should not be called directly.

    Declaration

    Objective-C

    - (void)setSelected:(BOOL)selected animated:(BOOL)animated;

    Swift

    func setSelected(selected: AnyObject!, animated: AnyObject!)
  • Setting this property to YES will make the view draggable. Long-press followed by a pan gesture will start to move the view around the map. -mapView:didDragAnnotationView:toCoordinate: will be called when a view is dropped.

    Declaration

    Objective-C

    @property (getter=isDraggable, assign, readwrite, nonatomic) BOOL draggable;

    Swift

    var draggable: Int32 { get set }
  • All states are handled automatically when draggable is set to YES. Custom animations can be achieved by overriding setDragState:animated:

    Declaration

    Objective-C

    @property (readonly, nonatomic) MGLAnnotationViewDragState dragState;

    Swift

    var dragState: Int32 { get }
  • Called when the dragState changes.

    Implementer may override this method in order to customize animations in subclasses.

    Declaration

    Objective-C

    - (void)setDragState:(MGLAnnotationViewDragState)dragState
                animated:(BOOL)animated;

    Swift

    func setDragState(dragState: AnyObject!, animated: AnyObject!)
  • Setting this property to YES will cause the annotation view to shrink as it approaches the horizon and grow as it moves away from the horizon when the associated map view is tilted. Conversely, setting this property to NO will ensure that the annotation view maintains a constant size even when the map view is tilted. To maintain consistency with annotation representations that are not backed by an MGLAnnotationView object, the default value of this property is YES.

    Declaration

    Objective-C

    @property (getter=isScaledWithViewingDistance, assign, readwrite, nonatomic)
        BOOL scalesWithViewingDistance;

    Swift

    var scalesWithViewingDistance: Int32 { get set }
  • Called when the view is removed from the reuse queue.

    The default implementation of this method does nothing. You can override it in your custom annotation views and use it to put the view in a known state before it is returned to your map view delegate.

    Declaration

    Objective-C

    - (void)prepareForReuse;

    Swift

    func prepareForReuse()