当我没有在MKMapView
上设置委托但添加注释时,他们的图像如下:
但是,如果我像这样返回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
}
然后图标看起来像一个垂直的针脚:
我知道我可以在MKAnnotationView
上使用自定义图像。但是,我想要默认的,除了我希望它看起来像第一个而不是第二个,但我也想自定义标注。我怎样才能实现这一目标?
第一张图片属于MKMarkerAnnotationView。所以要求它,而不是MKPinAnnotationView。