MKMapView未在Pan上调用regionDidChangeAnimated [英] MKMapView Not Calling regionDidChangeAnimated on Pan

查看:157
本文介绍了MKMapView未在Pan上调用regionDidChangeAnimated的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an app with a MKMapView and code that is called each time the map changes locations (in regionDidChangeAnimated). When the app initially loads, regionDidChangeAnimated is called on pans (swipes), pinches, taps and buttons that explicitly update the map coordinates. After loading other views and coming back to the map the regionDidChangeAnimated is only called for taps and the buttons that explicitly update the map. Panning the map and pinches no longer call regionDidChangeAnimated.

我看过这个 stackoverflow帖子没有解决这个问题。该论坛发布在 devforums iphonedevsdk 也没有用。有谁知道导致这个问题的原因?我没有向MKMapView添加任何子视图。

I have looked at this stackoverflow post which did not solve this issue. The forum posts on devforums and iphonedevsdk also did not work. Does anyone know what causes this issue? I am not adding any subviews to MKMapView.

推荐答案

我不想最初这样做,但它似乎工作到目前为止没有问题(取自相关的devforums帖子):

I did not want to initially do it this way, but it appears to work with no problems so far (taken from devforums post in question):

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

Add the UIGestureRecognizerDelegate to your header. Now add a check for the version number... If we're on iOS 4 we can do this:

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

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

Add the delegate methods to handle the gestures:

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

这篇关于MKMapView未在Pan上调用regionDidChangeAnimated的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆