Thanks to Anna for such a wonderful answer! Here is the version of Swift, if anyone is interested (the answer has been updated to Swift 4.1 syntax).
Creating a UILongPressGestureRecognizer:
let longPressRecogniser = UILongPressGestureRecognizer(target: self, action: #selector(MapViewController.handleLongPress(_:))) longPressRecogniser.minimumPressDuration = 1.0 mapView.addGestureRecognizer(longPressRecogniser)
Gesture Processing:
@objc func handleLongPress(_ gestureRecognizer : UIGestureRecognizer){ if gestureRecognizer.state != .began { return } let touchPoint = gestureRecognizer.location(in: mapView) let touchMapCoordinate = mapView.convert(touchPoint, toCoordinateFrom: mapView) let album = Album(coordinate: touchMapCoordinate, context: sharedContext) mapView.addAnnotation(album) }
Vlad Spreys Apr 6 '15 at 6:24 2015-04-06 06:24
source share