UILongPressGestureRecognizer does not work on MapKit (adapter)

35 Views Asked by At

I have a view controller which gets an adapter object to be able to use MapKit.

On that adapter I implement 2 gesture (long press + tap) as always but only long press does not work.

How I prepare gestures:

private func prepareGestures(on pinView: PinViewProtocol) {
    let longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress(sender:)))
    longPressGesture.delegate = self
    longPressGesture.minimumPressDuration = Constants.longPressDuration
    
    let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(sender:)))
    tapGesture.delegate = self
    
    pinView.addGestureRecognizers([tapGesture, longPressGesture])
}

How I add:

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    guard let annotation = annotation as? MyPinAnnotation else {
        return nil
    }
    prepareGestures(on: pinView)
    return pinView
}

How I add that object in my view controller:

private func configureMapView() {
    mapViewAdapter = TestMapViewAdapter(mapView: mapView)
}
0

There are 0 best solutions below