Y
Y
yadaby2021-03-16 18:52:59
Yandex maps
yadaby, 2021-03-16 18:52:59

iOS. YandexMapsMobile. How to handle gestures on a map with UIGestureRecognizer?

The map stops recognizing gestures after the first move/tap/gesture.
Procedure:
- go to the map
- pull to move the
first time everything works. After the first one, the gesture event handler works, but the map does not move / does not react
Please help me figure out what's wrong.

class MapViewController {
    // Map
    private let mapView = YMKMapView(frame: .zero)...


...
let tapInterceptor = WildCardGestureRecognizer(target: nil, action: nil)
tapInterceptor.gestureDelegate = self
mapView.addGestureRecognizer(tapInterceptor)
...


extension MapViewController: WildCardGestureDelegate {
    func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) {
        output.touchesBegan()
    }

    func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) {
    func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent) {
}


public class WildCardGestureRecognizer: UIGestureRecognizer {
    public var gestureDelegate: WildCardGestureDelegate!

    override public init(target: Any?, action: Selector?) {
        super.init(target: target, action: action)
        cancelsTouchesInView = false
    }

    override public func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) {
        super.touchesBegan(touches, with: event)
        gestureDelegate.touchesBegan(touches, with: event)
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question