我点击标注视图显示的注释引脚,但是当我选择注释引脚时,前一个视图不会关闭。
视图控制器
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
// 1
if view.annotation is MKUserLocation
{
// Don't proceed with custom callout
return
}
// 2
let pimAnnotation = view.annotation as! AnnotationPin
let views = Bundle.main.loadNibNamed("CalloutView", owner: nil, options: nil)
let calloutView = views?[0] as! CalloutViewController
calloutView.titleXib.text = pimAnnotation.title
calloutView.subtitleXib.text = pimAnnotation.subtitle
calloutView.imageXib.image = pimAnnotation.image
// 3
calloutView.center = CGPoint(x: view.bounds.size.width / 2, y: -calloutView.bounds.size.height*0.52)
view.addSubview(calloutView)
mapView.setCenter((view.annotation?.coordinate)!, animated: true)
}
func mapView(_ mapView: MKMapView, didDeselect view: MKAnnotationView) {
if view.isKind(of: CalloutAnnotationView.self)
{
for subview in view.subviews
{
subview.removeFromSuperview()
}
}
}
出了什么问题