点击自定义标注后,MKMapKit regionDidChangeAnimated停止

时间:2012-06-09 00:13:48

标签: objective-c ios mkannotationview mapkit

我正在实现一个自定义的MKAnnotationView标注,其中包含此处解释的代码(Jacob的一个),它实际上会在选择Annotation时放置另一个Custom AnnotationView:

MKAnnotationView - Lock custom annotation view to pin on location updates

一切正常,但我有一些奇怪的行为。点击自定义标注后,它将关闭标注,但之后不再调用regionDidChangeAnimated委托方法。

我错过了什么?我可以照常平移地图,但它不会调用该委托方法。虽然如果放大或缩小它会被调用。

在为我正在放置的AnnotationView添加自定义CallOut之前,这种情况从未发生过。

提前谢谢。

问候,艾伦//

1 个答案:

答案 0 :(得分:2)

我从您提到的链接下载了XCode项目,并且能够重现错误。以下答案有一个适合我的解决方法

MKMapView Not Calling regionDidChangeAnimated on Pan

为方便起见,我想重复解决方案,以及我如何在上述项目中应用它

CustomCalloutViewController.h添加UIGestureRecognizerDelegate

@interface CustomCalloutViewController : UIViewController 
<MKMapViewDelegate, UIGestureRecognizerDelegate>

在方法CustomCalloutViewController.m的{​​{1}}中,在viewDidLoad

之前添加
[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]; } 添加以下内容

CustomCalloutViewController.m

编辑:我找到了另一种解决方法here(所有内容都在底部,也提到了上述解决方法)。我没试过,但听起来很有意思。我在这里重复一遍:

  

我的解决方法很简单:在视图控制器中,在viewDidAppear:中创建MKMapView,并在viewDidDisappear中将其销毁:我意识到这对于那些使用Interface Builder的人来说并不是一个友好的解决方法,但在我看来,这是保存应用内存最干净,也可能是最好的方法。

相关问题