1

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.

Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
Byteros
  • 123
  • 1
  • 17

1 Answers1

1

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.

Community
  • 1
  • 1
Felix
  • 35,354
  • 13
  • 96
  • 143
  • Good idea... I think your code it's ok. I will test tomorrow. For the zoom scale i have studied the code of troy brant and i will use a reverse version of yours algorithm: http://troybrant.net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/ The only remaining problem is that it is impossible for me to set the maximum zoom level automatically for each coordinate, since the maximum zoom changes according to areas of the planet ... I'll invent something. Thanks again. – Byteros Mar 13 '11 at 22:58
  • I dont' think this is a good idea. There is some lag between this delegate method and the gesture event, which would make it hard to use for users. – David Dec 10 '12 at 13:15