MKMapView 未在平移上调用 RegionDidChangeAnimated

发布于 2025-01-02 13:36:20 字数 685 浏览 2 评论 0原文

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

我看过这个stackoverflow帖子,它没有解决这个问题。该论坛在 devforumsiphonedevsdk 也不起作用。有谁知道导致这个问题的原因是什么?我没有向 MKMapView 添加任何子视图。

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丑丑阿 2025-01-09 13:36:20

我最初不想这样做,但到目前为止它似乎没有任何问题(取自相关的 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;
}

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):

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文