gpt4 book ai didi

objective-c - MKMapKit regionDidChangeAnimated 在点击自定义标注后停止

转载 作者:可可西里 更新时间:2023-11-01 03:58:29 25 4
gpt4 key购买 nike

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

MKAnnotationView - Lock custom annotation view to pin on location updates

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

我是不是漏了什么?我可以像往常一样平移 map ,但它不会调用该委托(delegate)方法。尽管如果放大或缩小它确实会被调用。

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

提前致谢。

问候,艾伦//

最佳答案

我从您提到的链接下载了 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 (在底部也提到了上述解决方法)。我没有尝试过,但听起来很有希望。我在这里重复一遍:

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.

关于objective-c - MKMapKit regionDidChangeAnimated 在点击自定义标注后停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10957384/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com