Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MKMapKit regionDidChangeAnimated stops after tapping custom callout

I'm implementing a custom MKAnnotationView callout with the code explained here (Jacob's one), which actually places another Custom AnnotationView as the Annotation is selected:

MKAnnotationView - Lock custom annotation view to pin on location updates

Everything works just fine, but i've got some strange behavior. After tapping the custom callout, it will dismiss the callout but the regionDidChangeAnimated delegate method stops getting called at all afterwards.

I'm i missing something? I can pan the map as usual, but it won´t call that delegate method. Though if a do a zoom in or out it does gets called.

Prior to adding a custom CallOut for the AnnotationView's i'm placing, this never happened.

Thx in advance.

Regards, Alan //

like image 603
Alan Kennedy Avatar asked Jun 09 '12 00:06

Alan Kennedy


1 Answers

I downloaded the XCode project from the link you mentioned and was able to reproduce the error. The following answer has a workaround that worked for me

MKMapView Not Calling regionDidChangeAnimated on Pan

For convenience I want to repeat the solution and how I applied it in the mentioned project

In CustomCalloutViewController.h add UIGestureRecognizerDelegate

@interface CustomCalloutViewController : UIViewController 
<MKMapViewDelegate, UIGestureRecognizerDelegate>

In CustomCalloutViewController.m in method viewDidLoad add before [super viewDidLoad];

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];
}

Then still in CustomCalloutViewController.m add the following

#pragma mark -
#pragma mark Gesture Recognizers

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

- (void)panGestureCaptured:(UIPanGestureRecognizer*)gesture{
    if(UIGestureRecognizerStateEnded == gesture.state){


        NSLog(@"panGestureCaptured ended");
        // *************** Here it is *********************
        ///////////////////[self doWhatYouWouldDoInRegionDidChangeAnimated];
        // *************** Here it is *********************
    }
}

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

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

Edit: I have found another workaround here (all down at the bottom the above workaround is mentioned, too). I did not try out, but sounds promissing. I repeat it here:

My workaround is simple: In your view controller, create the MKMapView in viewDidAppear:, and destroy it in viewDidDisappear:. I realize this isn't a friendly workaround for those using Interface Builder, but, in my view, it's the cleanest, and probably the best way to conserve memory in your app.

like image 150
hol Avatar answered Sep 20 '22 03:09

hol