我有一个带有MKMapView的应用程序和每次地图更改位置时调用的代码(在regionDidChangeAnimated中)。应用程序最初加载时,将在显式更新地图坐标的平移(滑动),捏合,点击和按钮上调用regionDidChangeAnimated。加载其他视图并返回到地图后,仅调用tapDidChangeAnimated和显式更新地图的按钮。平移地图并捏不再调用regionDidChangeAnimated。
我看过这个没有解决这个问题的stackoverflow post。 devforums和iphonedevsdk上的论坛帖子也无效。有谁知道这个问题的原因是什么?我没有向MKMapView添加任何子视图。
答案 0 :(得分:3)
我最初不想这样做,但到目前为止似乎没有任何问题(取自相关的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];
}
添加委托方法来处理手势:
#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;
}