Z-index of iOS MapKit user location annotation

后端 未结 9 2324
天命终不由人
天命终不由人 2020-12-13 07:12

I need to draw the current user annotation (the blue dot) on top of all other annotations. Right now it is getting drawn underneath my other annotations and getting hidden.

9条回答
  •  渐次进展
    2020-12-13 07:33

    Just use the .layer.anchorPointZ property.

    Example:

     func mapView(_ mapView: MKMapView, didAdd views: [MKAnnotationView]) {
            views.forEach {
                if let _ = $0.annotation as? MKUserLocation {
                    $0.layer.anchorPointZ = 0
                } else {
                    $0.layer.anchorPointZ = 1
                }
            }
        }
    

    Here is there reference https://developer.apple.com/documentation/quartzcore/calayer/1410796-anchorpointz

提交回复
热议问题