Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MKMapView Not Calling regionDidChangeAnimated on Pan

I have an app with a MKMapView and code that is called each time the map changes locations (in regionDidChangeAnimated). When the app initially loads, regionDidChangeAnimated is called on pans (swipes), pinches, taps and buttons that explicitly update the map coordinates. After loading other views and coming back to the map the regionDidChangeAnimated is only called for taps and the buttons that explicitly update the map. Panning the map and pinches no longer call regionDidChangeAnimated.

I have looked at this stackoverflow post which did not solve this issue. The forum posts on devforums and iphonedevsdk also did not work. Does anyone know what causes this issue? I am not adding any subviews to MKMapView.

like image 911
brendan Avatar asked Feb 02 '12 22:02

brendan


1 Answers

I did not want to initially do it this way, but it appears to work with no problems so far (taken from devforums post in question):

Add the UIGestureRecognizerDelegate to your header. Now add a check for the version number... If we're on iOS 4 we can do this:

 if (NSFoundationVersionNumber >= 678.58){

      UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchGestureCaptured:)];
      pinch.delegate = self;          
      [mapView addGestureRecognizer:pinch];

      [pinch release];

      UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureCaptured:)];
      pan.delegate = self;
      [mapView addGestureRecognizer:pan];

      [pan release];
 }

Add the delegate methods to handle the gestures:

#pragma mark -
#pragma mark Gesture Recognizers

- (void)pinchGestureCaptured:(UIPinchGestureRecognizer*)gesture{
    if(UIGestureRecognizerStateEnded == gesture.state){
         ///////////////////[self doWhatYouWouldDoInRegionDidChangeAnimated];
    }
}

- (void)panGestureCaptured:(UIPanGestureRecognizer*)gesture{

    if(UIGestureRecognizerStateEnded == gesture.state){
        ///////////////////[self doWhatYouWouldDoInRegionDidChangeAnimated];
    }
}

-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
   return YES;
}

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:   (UITouch *)touch{
    return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer   shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer    *)otherGestureRecognizer{
    return YES;
}
like image 200
brendan Avatar answered Sep 21 '22 06:09

brendan