I'm having a strange problem with capturing drag/pan gestures on a GMSMapView through a Gesture Recognizer. This problem surfaced only after updating from GMS 1.2 to 1.3.1, where (quoting the documentation),
Touches are consumed more agressively by GMSMapView
I have a UIViewController holding a GMSMapView under its main view. I found GMSMapDelegate does not provide methods for handling drag/pan gestures, so I added a UIPanGestureRecognizer to the UIViewController, linked it to an IBAction selector, and set referencing outlet and outlet collection, as per the screenshot linked here: http://i.stack.imgur.com/gktoa.png
So any drag action would simply trigger the recognizeDragOnMap:
selector, as below:
-(IBAction)recognizeDragOnMap:(id)sender {
NSLog(@"recognizeDragOnMap");
UIGestureRecognizer *gestureRecognizer = (UIGestureRecognizer *)sender;
if (gestureRecognizer.state != UIGestureRecognizerStateEnded) {
NSLog(@"Still dragging");
return;
}
NSLog(@"DragEnded");
GMSCameraPosition *position;
if ((position = self.mapView.camera)) {
self.automaticCameraPositionChange = NO;
CLLocationCoordinate2D coordinate = [position targetAsCoordinate];
CLLocation *location = [[CLLocation alloc] initWithLatitude:coordinate.latitude longitude:coordinate.longitude];
[self.origin dragPinToLocation:location];
} else {
NSLog(@"No map camera");
}
}
This setup used to work perfectly under GMS 1.2.0. After the update, the GMSMapView responds to the gestures like it used to, however the method above never gets called!
Anyone have an idea what's up and/or how to fix it?
The user must press one or more fingers on a view while panning on the screen. A panning gesture is on continuous action when the user moves one or more fingers allowed (minimumNumberOfTouches) to enough distance for recognition as a pan.
A pan gesture occurs any time the user moves one or more fingers around the screen. A screen-edge pan gesture is a specialized pan gesture that originates from the edge of the screen. Use the UIPanGestureRecognizer class for pan gestures and the UIScreenEdgePanGestureRecognizer class for screen-edge pan gestures.
For version 1.4 or higher, you just have to set consumesGesturesInView = NO
in your GMSUISettings object.
If you do that, be aware that you will have to deal with events that could make your superview to do stuff when you just want to interact with the map... By that I mean, for example, that dragging a GMSMapView added to a scroll view will scroll the scroll view on drag!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With