0 Replies
      Latest reply on Nov 30, 2019 10:24 AM by ErikBooij
      ErikBooij Level 1 Level 1 (0 points)



        I'm running into an issue I don't quite understand. I'm using an `MKMapView` with a `UILongPressGestureRecognizer`. The problem is that every first touch after a long press seems to be missed or ignored.


        I've created a tiny little demo view controller in which it's reproducible (I've inlined the code in the post down below):




        After the long press target is executed. It first takes a touch on the map view for it to start recognizing gestures again (not just long presses, also all standard map interactions like pan, tilt, zoom, etc.).


        If I run this exact same code with a different kind of view (a standard `UIView` instead of the `MKMapView` for example), there's no problem.


        Does anyone have a clue what's going on here?


        (inline code sample in case that's easier)


        import MapKit
        import UIKit
        class MainController: UIViewController {
            private let label = UILabel()
            private var count = 0
            override func viewDidLoad() {
                view.backgroundColor = .white
                let mapView = MKMapView()
                mapView.translatesAutoresizingMaskIntoConstraints = false
                label.textAlignment = .center
                label.translatesAutoresizingMaskIntoConstraints = false
                    mapView.topAnchor.constraint(equalTo: view!.topAnchor),
                    mapView.leftAnchor.constraint(equalTo: view!.leftAnchor),
                    mapView.rightAnchor.constraint(equalTo: view!.rightAnchor),
                    mapView.bottomAnchor.constraint(equalTo: label.topAnchor),
                    label.leftAnchor.constraint(equalTo: view!.leftAnchor),
                    label.rightAnchor.constraint(equalTo: view!.rightAnchor),
                    label.bottomAnchor.constraint(equalTo: view!.bottomAnchor),
                    label.heightAnchor.constraint(equalToConstant: 50),
                let gestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(handleMapPress(sender:)))
                gestureRecognizer.minimumPressDuration = 0.3
            private func handleMapPress(sender: UIGestureRecognizer) {
                guard sender.state == .ended else {
                count += 1
                label.text = "Presses: \(count)"