Quickly adding single pin to MKMapView?

后端 未结 6 1167
孤城傲影
孤城傲影 2020-12-13 08:27

I have a GPS coordinate (latitude, longitude) and I quickly want to place a single pin on a MKMapView showing that position. Everything works just fine, but as I only need a

6条回答
  •  天涯浪人
    2020-12-13 08:42

    Since you want to animate the drop, you will need to implement viewForAnnotation as you've done because that property is NO by default.

    If you don't need to animate the drop, you could eliminate the viewForAnnotation method implementation completely and to disable the callout, set the annotation's title to nil or blank when adding the annotation instead.

    If you do need the pin drop animation and you're also showing the user's location (blue dot), you'll also need to check for MKUserLocation in viewForAnnotation and return nil.

    Otherwise, you could remove the whole viewForAnnotation method and the default red pin will appear without animation, the callout will show if title is not blank, and the user location will show as a blue dot.

提交回复
热议问题