Post

Replies

Boosts

Views

Activity

MKMapView unresponsive after long press
Hi!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):https://pastebin.com/JLBQwt7wAfter 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 view.addSubview(mapView) view.addSubview(label) NSLayoutConstraint.activate([ 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 mapView.addGestureRecognizer(gestureRecognizer) } @objc private func handleMapPress(sender: UIGestureRecognizer) { guard sender.state == .ended else { return } count += 1 label.text = "Presses: \(count)" } }
5
0
2.4k
Nov ’19