我正在UITapGestureRecognizer委托中创建一个带有标注的简单点注释.
我第一次点击地图时,引脚会出现带有标注,但标注会立即消失.
第二次点击相同的引脚时,标注出现并停留在那里,不知道为什么它会在第一次消失.
@IBAction func handleMapTouch(recognizer: UITapGestureRecognizer){
let view = recognizer.view
let touchPoint=recognizer.locationInView(view)
var touchCord=CLLocationCoordinate2D()
touchCord = mapView.convertPoint(touchPoint, toCoordinateFromView:
mapView)
mapView.removeAnnotations(mapView.annotations)
pointAnnotation.coordinate=touchCord
pointAnnotation.title="ABC"
pointAnnotation.subtitle="DEF"
mapView.addAnnotation(pointAnnotation)
mapView.selectAnnotation(pointAnnotation, animated: true)
}
Run Code Online (Sandbox Code Playgroud)