Background
- I have a map (MapKit) with a takeaway (a custom view has been added to the annotation) - I was able to make sure that the "long print" gesture made above the callout view is not selected (see below using "shouldReceiveTouch")
Question
What I cannot do is do the same (i.e., Ignore) by double-clicking on the leader view, since the MapKit map still somehow selects and zooms out. I tried trapping the Double Tap sign however it does not seem to work.
Mapkit View Delegate Code
Configuring gesture recognizers
let longPressGR = UILongPressGestureRecognizer(target: self, action: "longPressAction:")
longPressGR.minimumPressDuration = 1
longPressGR.delegate = self
self.mapView.addGestureRecognizer(longPressGR)
let doubleTapGR = UITapGestureRecognizer(target: self, action: "doubleTapAction:")
doubleTapGR.numberOfTapsRequired = 2
doubleTapGR.delegate = self
self.mapView.addGestureRecognizer(doubleTapGR)
Implement "shouldReceiveTouch" for UIGestureRecognizerDelegate
extension GCMapViewHelper : UIGestureRecognizerDelegate {
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
guard let touchesView = touch.view else { fatalError("ERROR: Touch event received was nil") }
for annotation in self.mapView.selectedAnnotations {
if annotation is GCAnnotation {
let annotationView = self.mapView.viewForAnnotation(annotation)
if let annotationView = annotationView {
if (touchesView.isDescendantOfView(annotationView)) {
return false
}
}
}
}
return true
}
}
EDIT: , , ... ? .
doubleTapGR.numberOfTapsRequired = 2
2 :
, , :
* "longPressAction" - /
* "tapAction" - , MKMapView. , .
import UIKit
import MapKit
class ViewController: UIViewController {
@IBOutlet weak var mapview: MKMapView!
func longPressAction() {
print("longPressAction")
}
func tapAction() {
print("tapAction")
}
override func viewDidLoad() {
super.viewDidLoad()
let longPressGR = UILongPressGestureRecognizer(target: self, action: "longPressAction")
longPressGR.minimumPressDuration = 1
self.mapview.addGestureRecognizer(longPressGR)
let tapGR = UITapGestureRecognizer(target: self, action: "tapAction")
tapGR.numberOfTapsRequired = 2
self.mapview.addGestureRecognizer(tapGR)
}
}