Byteros
Byteros

Reputation: 123

Gesture Reocognizer on MKMapView - iPhone

I have a mapView, in my mapView you can zoom with double tap, pinch, UIButton (+ and -) and with an UISlider. Now... I want recognize the doubletap and the pinch, to refresh the position of UISlider... I use a NSInteger variable called zoomLevel to make this.

I have tried two way, but not working:

1)

    UIGestureRecognizer *recognizer;


// taps
recognizer = [[ UITapGestureRecognizer alloc] initWithTarget:self  action:@selector(handleTap)];
tapGR = (UITapGestureRecognizer *)recognizer;
tapGR.numberOfTapsRequired = 2;
tapGR.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:tapGR]; 
[recognizer release];

2)

- (void)touchesEnded:(NSSet *)touches withEvent: (UIEvent *) event{
    UITouch* touch = [[event allTouches] anyObject];
    NSLog(@"2 taps");
    if(touch.tapCount == 2 ){
        NSLog(@"2 taps");
        [self zoomLevelWithMapView:mappa];
    }

Can someone help me? Better with pratical example Thank you.

Upvotes: 1

Views: 2083

Answers (1)

Felix
Felix

Reputation: 35384

Recognizing the change of zoom scale with UIGestureRecognizer is a bad idea.

Better use the MKMapView delegate method that is called when the region displayed by the map view is about to change.

- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated {
    // detect zoom scale and update slider
}

Use the method in this answer to detect the zoom scale.

Upvotes: 1

Related Questions