我有以下代码为MapView创建自定义标注。
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
guard let annotation = view.annotation as? FloodAnnotation else {
return
}
let annotationPoint = mapView.convert((view.annotation?.coordinate)!, toPointTo: mapView)
// get the location of the point
var point = mapView.convert((view.annotation?.coordinate)!, toPointTo: mapView)
let fancyCalloutView = FancyCalloutView(frame: CGRect(x: 0, y: 0, width: 100, height: 50))
fancyCalloutView.center = point
view.addSubview(fancyCalloutView)
}
这导致以下结果:
单击右侧注释时会显示标注。我相信这是因为标注是注释视图的子视图,因此使用该坐标系来定位自己。如何让标注出现在注释视图的上方?