gpt4 book ai didi

ios - MKMapView 不在 Pan 上调用 regionDidChangeAnimated

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

我有一个带有 MKMapView 的应用程序和每次 map 更改位置时调用的代码(在 regionDidChangeAnimated 中)。当应用程序最初加载时,regionDidChangeAnimated 会在显式更新 map 坐标的平移(滑动)、捏合、点击和按钮上被调用。在加载其他 View 并返回到 map 后,regionDidChangeAnimated 仅在点击和明确更新 map 的按钮时被调用。平移 map 和捏合不再调用 regionDidChangeAnimated。

我看过这个stackoverflow post这并没有解决这个问题。论坛发帖devforumsiphonedevsdk也没有用。有谁知道是什么导致了这个问题?我没有向 MKMapView 添加任何 subview 。

最佳答案

我最初不想这样做,但到目前为止它似乎没有任何问题(摘自有问题的 devforums 帖子):

将 UIGestureRecognizerDelegate 添加到您的标题中。现在添加版本号检查...如果我们在 iOS 4 上,我们可以这样做:

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

添加委托(delegate)方法来处理手势:

#pragma mark -
#pragma mark Gesture Recognizers

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

- (void)panGestureCaptured:(UIPanGestureRecognizer*)gesture{

if(UIGestureRecognizerStateEnded == gesture.state){
///////////////////[self doWhatYouWouldDoInRegionDidChangeAnimated];
}
}

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

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

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

关于ios - MKMapView 不在 Pan 上调用 regionDidChangeAnimated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9120961/

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