3

I am working on Google maps api. Currently when we try to drag the marker, we have to hold for few seconds and then mapView goes up by like few points then we can drag the marker. I would like to change this behavior.

Can I override the minimumPressDuration of UILongPressGestureRecognizer in mapView? Like this in some way:

for (id gestureRecognizer in mapView.gestureRecognizers)
    {
        if ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]])
        {
            gestureRecognizer.minimumPressDuration = 0.0f;
        }
    }

Basically I don't want to hold marker for few second and then start dragging it, it should be drag-able instantaneousl and Map should not move during a drag. How do I achieve this?

Sakir Sherasiya
  • 1,562
  • 1
  • 17
  • 31
NotABot
  • 516
  • 1
  • 8
  • 27

1 Answers1

1

try this on for size

func recursivlyPrint(subviews: [UIView]){
    for subview in subviews{
        if subview.gestureRecognizers != nil{
            for gesture in subview.gestureRecognizers!{
                print(gesture)
                if gesture is UILongPressGestureRecognizer{
                    (gesture as! UILongPressGestureRecognizer).minimumPressDuration = 0.0
                }
            }
        }
        if subview.subviews.count>0{
            recursivlyPrint(subviews: subview.subviews)
        }
    }
}

Run it on the subviews of the mapView after you add your markers. This isn't the best way to do it. The better way to do it would be to access the selector name of the action of the gesture and filter by that (maybe there are other long press gestures that are not related to the markers that might screw with the mapView as a whole). Getting the Action of UIGestureRecognizer in iOS this method uses private properties in the gesture recognizer class which might be discouraged(maybe?)

Edit: You might also want to filter by the type of the subview

Community
  • 1
  • 1
DatForis
  • 1,331
  • 12
  • 19
  • Yeah this works but mapView still bounces while dragging a marker. And tapping on a map anywhere stopped working now. `- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate` does not get a call. – NotABot May 19 '17 at 14:04
  • @thewarri0r9 try to find the specific selector for the gesture recognizer. I imagine screwing with all the UILongPressGesture recognizers in the mapView might cause this unwanted behavior – DatForis May 22 '17 at 07:34
  • Okay I solved that problem by changing minimumPressDuration to 0.1. But still I am not able to remove mapView bounce animation when I try to drag marker. – NotABot May 22 '17 at 10:18