【问题标题】:MKMapKit regionDidChangeAnimated stops after tapping custom calloutMKMapKit regionDidChangeAnimated 在点击自定义标注后停止
【发布时间】:2012-06-09 00:13:47
【问题描述】:

我正在使用此处解释的代码(Jacob 的代码)实现自定义 MKAnnotationView 标注,它实际上放置了另一个自定义 AnnotationView 作为选择的注释:

MKAnnotationView - Lock custom annotation view to pin on location updates

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

我错过了什么?我可以像往常一样平移地图,但它不会调用该委托方法。虽然如果 a 进行放大或缩小,它确实会被调用。

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

提前致谢。

问候,艾伦 //

【问题讨论】:

  • 我们实际上会发现这发生在每个人都用作 iOS 5.1 模拟器上的模板的原始项目中,所以这不是我的代码。我会尝试用观察者替换 didSelectView 看看会发生什么。
  • 我也遇到了这个问题,它似乎发生在单击图钉并在加载一组新图钉时按住。

标签: objective-c ios mkannotationview mapkit


【解决方案1】:

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

MKMapView Not Calling regionDidChangeAnimated on Pan

为方便起见,我想重复该解决方案以及我在上述项目中的应用方式

CustomCalloutViewController.h 中添加UIGestureRecognizerDelegate

@interface CustomCalloutViewController : UIViewController 
<MKMapViewDelegate, UIGestureRecognizerDelegate>

CustomCalloutViewController.m 方法中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添加以下

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

编辑:我找到了另一种解决方法here(在底部也提到了上述解决方法)。我没有尝试,但听起来很有希望。我在这里重复一遍:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 1970-01-01
    • 2018-01-04
    • 1970-01-01
    相关资源
    最近更新 更多