Question


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.

Was it helpful?

Solution

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.

OTHER TIPS

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
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top