-1

When the animation is executing , i try to click the moving annotationView ,but cannnot be selected, the mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) hasn't been called

func addMoveAnimation() {
        guard let ano = annotation as? Annotation else {
            return
        }
        animator = UIViewPropertyAnimator.init(duration: 10, curve: .linear, animations: {
            ano.coordinate = CLLocationCoordinate2D(latitude: 32.449819, longitude: 112.292726)
        })
        animator?.startAnimation()
        animator?.addCompletion({ (position) in
            print(position.des,"coor:", ano.coordinate)
        })
    }
Kaushik Makwana
  • 1,329
  • 2
  • 14
  • 24
chunxi
  • 19
  • 2

1 Answers1

0

i try to add a UITapGestureRecognizer for the annotationView, and it really works, but then quickly changed to be deseleted, and the mapView(_ mapView: MKMapView, didDeselect view: MKAnnotationView) also be called

@objc func handleGes() {
        print("tap ges click")
        removeAnimation()
        let currentFrame =  (layer.presentation() as! CALayer).frame
        layer.removeAllAnimations()
        let point = CGPoint.init(x: currentFrame.midX, y: currentFrame.midY)
        let coor = mapView?.convert(point, toCoordinateFrom: mapView)
        guard let ano = annotation as? Annotation, let coordinate = coor else {
            return
        }
        ano.coordinate = coordinate
        print(ano.coordinate)
        mapView?.selectAnnotation(ano, animated: false)
    }
chunxi
  • 19
  • 2