Why is there a double tap in this iOS code?

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

// Gesture Recogniser (Long Press)
let longPressGR = UILongPressGestureRecognizer(target: self, action: "longPressAction:")
longPressGR.minimumPressDuration = 1
longPressGR.delegate = self
self.mapView.addGestureRecognizer(longPressGR)

// Gesture Recogniser (Double Tap)
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")  // ** Not appearing in console ** 
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Gesture Recogniser (Long Press)
        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)

        //tapGR.requireGestureRecognizerToFail(longPressGR)

    }

}
+1
1

- .

, , .

, , :

import UIKit
import MapKit

class StarAnnotation : NSObject, MKAnnotation {
    let title: String?
    let coordinate: CLLocationCoordinate2D

    init(title: String, coordinate: CLLocationCoordinate2D) {
        self.title = title
        self.coordinate = coordinate
        super.init()
    }
}

class StarAnnotationView : MKAnnotationView, UIGestureRecognizerDelegate {
    override init(annotation: MKAnnotation?, reuseIdentifier: String?) {
        super.init(annotation: annotation, reuseIdentifier: reuseIdentifier)
        self.image = UIImage(named: "star")

        // Gesture Recogniser (Long Press)
        let longPressGR = UILongPressGestureRecognizer(target: self, action: "longPressAction:")
        longPressGR.minimumPressDuration = 1
        longPressGR.delegate = self
        self.addGestureRecognizer(longPressGR)

        // Gesture Recogniser (Double Tap)
        let doubleTapGR = UITapGestureRecognizer(target: self, action: "doubleTapAction:")
        doubleTapGR.numberOfTapsRequired = 2
        doubleTapGR.delegate = self
        self.addGestureRecognizer(doubleTapGR)

    }

    override init(frame: CGRect) {
        super.init(frame: frame)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func doubleTapAction(recognizer: UITapGestureRecognizer) {
        if recognizer.numberOfTapsRequired == 2 {
            print("double tapped")
        }
    }

    func longPressAction(recognizer: UILongPressGestureRecognizer) {
        print("long pressed")
    }
}

class ViewController: UIViewController, MKMapViewDelegate {

    @IBOutlet weak var mapView: MKMapView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // set up map view and sample annotation
        let operaHouseCoord = CLLocationCoordinate2D(latitude: -33.8587, longitude: 151.2148)
        let span = MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01)
        let operaHouseAnnotation = StarAnnotation(title: "Opera House", coordinate: operaHouseCoord)
        mapView.region = MKCoordinateRegion(center: operaHouseCoord, span: span)
        mapView.delegate = self
        mapView.addAnnotation(operaHouseAnnotation)
    }

    func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
        if let annotation = annotation as? StarAnnotation {
            let identifier = "star"
            if let dequeuedView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier) as? StarAnnotationView {
                dequeuedView.annotation = annotation
                return dequeuedView
            } else {
                let view = StarAnnotationView(annotation: annotation, reuseIdentifier: identifier)
                view.canShowCallout = true
                return view
            }
        }
        return nil
    }
}
+1

All Articles