我用来处理水龙头的功能:
func mapView(_ mapView: MKMapView, didDeselect view: MKAnnotationView) {
if view == customCallout {
return
} else {
customCallout?.removeFromSuperview()
}
}
在这种情况下,它在两个水龙头上都删除了自定义标注。在这里,我创建了标注:
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
if view.annotation is MKUserLocation {
return
}
//this creates the callout
let views = Bundle.main.loadNibNamed("CustomCalloutView", owner: nil, options: nil)
let calloutView = views?[0] as! CustomCalloutView
calloutView.delegate = self
customCallout = calloutView
}
如果我在自定义标注视图内部点击,如何实现呢?如果我在外部点击,它会消失呢?
我有一些图钉。当我单击Pin时,自定义标注将显示为UIView。当我在calloutView内部点击时,什么也不会发生。如果我在视图外部点击,则自定义calloutView ...
TapGestureRecognizer
:hitTest
方法,该方法包括自定义标注中的匹配。否则,触摸不会被识别为注释视图和/或标注的一部分,而是在地图上。