小编nis*_*pta的帖子

出现MKMapView上的PointAnnotation标注,然后立即消失

我正在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)

annotations mkmapview ios callout swift

7
推荐指数
1
解决办法
599
查看次数

标签 统计

annotations ×1

callout ×1

ios ×1

mkmapview ×1

swift ×1