0
votes

I have a google maps in which I want it to recognise long press gestures on markers. For the mean time I just want to map to respond to a long press gesture. I think I have followed the steps to implementing it correctly but don't seem to be getting a response from the long press and not sure why- could it be because I am testing on simulator that it doesn't recognise click as long press? Anyway here is the method I used below so if anybody can see if there is anything I've missed, please let me know.

1.) dragged long tap gesture recogniser from object library into my maps view in the main storyboard.

2.) this put the gestureRecognizers --> map View into my referencing outlet connection

3.) set the min duration to 0.5sec and enabled both touch and tap recognizers to 1.

4.) in the viewcontroller which contains my mapView typed in:

     @IBAction func handleLongtap(recognizer: UILongPressGestureRecognizer) {
    print("PRESSED")
}

5.) then back on the main storyboard did control drag Long Press Gesture recognizer to the view controller and selected "handleLongtap:" which put 'handleLongTap --> longPressGesture" into my view controller 'received actions'

Despite there being no error- i do not get "PRESSED" in my terminal when i do a long click on simulator. Any idea what is going wrong?

1

1 Answers

0
votes

You could try adding the gesture recognizer in code:

let longPress = UILongPressGestureRecognizer()
longPress.addTarget(self, action: ViewController.handleTap)
yourPin.addGestureRecognizer(longPress)

func handleTap() {
    print("Tapped")
}

And just tweak it as you need.