如何使注释看起来像当前位置指示符?

How do I make the annotations look like the current location indicator?

我正在尝试自定义地图上的注释,而不是图钉,我希望注释看起来像当前位置指示器。我该怎么做?任何建议都会很棒!

一般来说,您可以使用扩展 MKPointAnnotation 的自定义注释对象。但是如果你只需要改变 pin 图像你可以避免子类化并且只实现这个方法

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {

    let identifier = "MyPin"

    if annotation.isKindOfClass(MKUserLocation) {
        return nil
    }

    var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier)

    if let annotationView = annotationView {
        annotationView.annotation = annotation
    } else {
        annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)
        annotationView.image = UIImage(named: "myPinImage")
    }

    return annotationView
}

因此,您只要找到正确的图片并用它替换图钉就足够了。 但是如果你想关注默认 currentLocation 图片的可能变化,你可以重用默认视图

let annotationView = mapView.viewForAnnotation(mapView.userLocation());