Reputation: 3931
I have a single view on my iOS application, with a mapView in it.
When adding a tap or long press recognizer, the events are properly called.
But not with the pinch event...
UIPinchGestureRecognizer *handlePinchGesture=[[UIPinchGestureRecognizer alloc]initWithTarget:mapView action:@selector(handleGesture:)];
[mapView addGestureRecognizer:handlePinchGesture];
Any idea what I should add ? Thanks.
Upvotes: 0
Views: 1550
Reputation: 53551
Assuming your mapView
is an MKMapView
, it has its own pinch gesture recognizer for zooming the map.
If you want to add your own recognizer, you have to allow it to recognize simultaneously with the other (mapview-controlled) recognizer. Set your gesture recognizer's delegate
and implement gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
(you can just always return YES
).
You should also probably set self
as the gesture recognizer's target
and not the mapView
.
Upvotes: 3
Reputation: 14834
In the handleGesture method did you do something like this:
CGFloat beginPinch; //declare this as your ivars
-(void)handleGesture:(UIPinchGestureRecognizer *)pinchRecognizer
{
if (pinchRecognizer.state == UIGestureRecognizerStateBegan)
{
beginPinch = pinchRecognizer.scale;
}
else if (pinchRecognizer.state == UIGestureRecognizerStateEnded)
{
if (pinchRecognizer.scale < beginPinch)
{
//do your stuff
}
}
}
Upvotes: 1