在IOS开发中,我们可以利用MapKit使用苹果的地图,在地图上我们可以添加自定义的图钉,假如图钉都加在一起,互相就会有覆盖的情况,我们可以用displayPriority 优先级来解决这个问题。
// 自定义的MKAnnotation作成 func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { guard annotation is MKPointAnnotation else { return nil } let identifier = "Annotation" + String(arc4random()) var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) if annotationView == nil { annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier) annotationView!.canShowCallout = true let btn = UIButton(type: .detailDisclosure) annotationView!.rightCalloutAccessoryView = btn } else { annotationView!.annotation = annotation } if annotation.annotationStatus == "normal" { let image = UIImage(named: "图钉图片名字")! annotationView!.image = image.scaleImage(scaleSize: annotation.iconScaleSize) // 这里设定图钉的优先级 annotationView!.displayPriority = .defaultLow // 也可以自定义displayPriority // annotationView!.displayPriority = .init(30) } if annotation.annotationStatus == "selected" { let image = UIImage(named: "图钉图片名字")! annotationView!.image = image.scaleImage(scaleSize: 2) // 这里设定图钉的优先级 annotationView!.displayPriority = .defaultHigh // 也可以自定义displayPriority // annotationView!.displayPriority = .init(40) } return annotationView } }