MapView viewForAnnotation在圆圈中显示白色图钉(默认)

问题描述 投票:0回答:1

当我没有在MKMapView上设置委托但添加注释时,他们的图像如下:

Default view

但是,如果我像这样返回MKAnnotationView

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    if annotation.isKind(of: MKUserLocation.self) {
        return nil
    }

    guard annotation is MKPointAnnotation else { return nil }

    let identifier = "Annotation"
    var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)

    if annotationView == nil {
        annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
        annotationView!.collisionMode = .circle
        annotationView!.canShowCallout = true
    } else {
        annotationView!.annotation = annotation
    }

    return annotationView
}

然后图标看起来像一个垂直的针脚:

customised

我知道我可以在MKAnnotationView上使用自定义图像。但是,我想要默认的,除了我希望它看起来像第一个而不是第二个,但我也想自定义标注。我怎样才能实现这一目标?

swift mkmapview
1个回答
1
投票

第一张图片属于MKMarkerAnnotationView。所以要求它,而不是MKPinAnnotationView。

© www.soinside.com 2019 - 2024. All rights reserved.