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 //
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.
链接地址: http://www.djcxy.com/p/67278.html上一篇: 自定义地图标注视图隐藏在自来水中