Reputation: 2577
I'm trying to overlay a UIView over a google GMSMapView. The goal is to intercept swipes in order to know when the map is being moved manually. (I know I could check -mapView:willMove: but that gets called regardless of whether the map is moving programmatically or as result of manual touch). I'm programmatically re-centering the map as the position updates--because Google doesn't do it for you like Apple does. Like every map program out there, I want to stop centering on the current position as soon as the user manually moves the map. The only way I can think to capture that occurrence (short of switching to mapkit or waiting for Google to add to the API) is to capture a swipe as it's going past a view laid over the map.
To clarify, my question is how do I lay a view over a google map, make it respond to a swipe and still allow that event to pass through to the GMSMapView?
Both my map and interceptView are sibling children of the main view. interceptView has a gestureRecognizer, is set to opaque, not hidden and userInteractionEnabled = YES. As such the interceptView picks up touch events just fine. But the map underneath doesn't move. If I set interceptView.userInteractionEnabled = NO, the map works fine.
"Passing touches" by overriding touchesBegan and calling GMSMapView's touchesBegan doesn't do anything. And overriding hitTest doesn't seem to be an option because I can't subclass GMSMapView. Has anyone done this? I know there's a lot on here about passing particular events through. I want to process a particular event on two views, one of which is Google's map layer which I can't modify the code of.
Upvotes: 4
Views: 1571
Reputation: 1532
Here is a delegate method check it
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate;
Upvotes: 1
Reputation: 2102
You can intercepte the tap using the GMSMapViewDelegete and implementing this method:
-(void)panoramaView:(GMSPanoramaView *)panoramaView didTap:(CGPoint)point;
Example:
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
CLLocationCoordinate2D panoramaNear = {latitudine,longitudine};
GMSPanoramaView *panoView = [GMSPanoramaView panoramaWithFrame:CGRectZero
nearCoordinate:panoramaNear];
[panoView setDelegate:self];
self.view = panoView;
}
-(void)panoramaView:(GMSPanoramaView *)panoramaView didTap:(CGPoint)point{
NSLog(@"Tap");
}
Upvotes: 0
Reputation: 41
mapView:willMove: receives a bool "gesture" which is true if the move was triggered by a user gesture and false if it wasn't. So you can stop re-centering the map only if "gesture" is true. That way you can be sure that the map is being moved manually.
Upvotes: 4