MKMapView RegionDidChangeAnimated 并不总是被调用!

发布于 2024-10-01 13:01:46 字数 82 浏览 2 评论 0原文

这让我很沮丧!

大多数时候它都会被调用,但随后它就会停止响应捏合。它将在屏幕旋转和双击上调用。不至于紧要关头!

帮助!

This is frustrating me!!!

It will be called most of the time but then it stops responding to the pinches. It will be called on a screen rotate and a double tap. Not to a pinch!

Help!

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

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

发布评论

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

评论(5

没企图 2024-10-08 13:01:46

我正在处理一些具有相同问题的代码,结果发现问题是带有 UIGestureRecognizer 的子视图已作为子视图添加到 MKMapView 中,有时,他们会导致某些委托方法不触发。

因此,请确保您没有向 MKMapView 添加子视图或任何内容。

希望这有帮助。

I was working on some code that had the same issue and turns out the problem was a subview with a UIGestureRecognizer had been added as a subview to MKMapView, and sometimes, they would cause some delegate methods not to fire.

So make sure you aren't adding subviews or anything to the MKMapView.

Hope this helps.

孤独难免 2024-10-08 13:01:46

我正在用代码移动地图,然后看来我需要调用

[mapView setNeedsDisplay];

After!

I was moving the map in code and then it appears I needed to call

[mapView setNeedsDisplay];

After!

无人问我粥可暖 2024-10-08 13:01:46

我认为这个问题可能与多线程有关。

今天早上我也遇到了同样的问题。我使用手势识别器来捕获长按事件,然后将图钉添加到地图视图。如果运行良好,但经过几轮后,该区域确实发生了更改方法停止被调用。

我在这里尝试了一些解决方案,但没有一个有效。然后我想起了之前遇到的关于操作的多线程性质的其他问题。因此,我尝试将长按操作中控制地图视图的代码移动到在主线程中运行的块。问题就解决了。

I think this problem may have something to do with multi-threading.

I had the same problem this morning. I use a gesture recognizer to capture long press event and then add a pin to the mapview. If works well but after a few rounds, the region did change method stop being called.

I tried a few solutions here but none works. Then I recalled some other issue I had before with multi-threading nature of actions. So I try to moved the code that controls the mapview in long press action to a block that runs in main thread. And the problem is solved.

不如归去 2024-10-08 13:01:46

我设法通过禁用touchesBeganCallback中的手势识别器

self.tapInterceptor.touchesBeganCallback = ^(NSSet *touches, UIEvent *event) {
    self.tapInterceptor.enabled = NO;
    // do something
};

并在regionDidChangeAnimated委托方法中重新启用它来解决这个问题

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
    self.tapInterceptor.enabled = YES;
    // do something
}

I managed to solve this problem by disabling the gesture recognizer within the touchesBeganCallback

self.tapInterceptor.touchesBeganCallback = ^(NSSet *touches, UIEvent *event) {
    self.tapInterceptor.enabled = NO;
    // do something
};

and reenabling it in the regionDidChangeAnimated delegate method

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
    self.tapInterceptor.enabled = YES;
    // do something
}
浪菊怪哟 2024-10-08 13:01:46

每当点击手势识别器添加到地图视图时,

recognizer.cancelsTouchesInView = NO;

如果您的业务逻辑允许在触摸地图视图时进行双重处理(通过 MKMapView 和手势识别器),则设置会解决问题
最近干扰该区域的[Will,Did]ChangeAnimated:)

Whenever a tap gesture recognizer added to the mapview, setting

recognizer.cancelsTouchesInView = NO;

takes care of the problem if your business logic allows for double processing if touches on mapview (by MKMapView AND the gesture recognizer
that was most recently interfering with the region[Will,Did]ChangeAnimated:)

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