Reputation: 526
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?
Upvotes: 3
Views: 411
Reputation: 1341
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
Upvotes: 1