MKMapView 和 setRegion:animated: 不更新地图视觉效果

发布于 2024-07-25 22:45:56 字数 1324 浏览 3 评论 0原文

问候! 我尝试在没有任何 Apple 代码示例的情况下使用 MKMapView,尽管还有一些其他代码示例的清晰度各异。 (我知道,“阅读友好手册。”我已经这样做了,但并不是 100% 清楚,所以请耐心等待我。)

情况如下。 我有一个 MKMapView 对象,其中添加了一组大约十个 MKPinAnnotation 对象。 到目前为止,一切都很好。 一切都被合理地分配/释放,并且似乎没有来自 Instruments 的任何抱怨。

初始显示时,我设置了一个 MKCooperativeRegion 对象,其中心点位于第一个引脚位置,(任意)跨度为 0.2 x 0.2。 然后我就喊:

[mapView setRegion:region animated:YES];
[mapView regionThatFits:region];

哇! 效果很好。

同时......我还有一个分段控件,允许移动到每个引脚位置。 因此,当我点击列表时,地图会通过一对新的调用 setRegion:animated:regionThatFits: 来动画显示每个新的图钉位置...或者至少这就是想法。

虽然地图确实“移动”到了新的图钉位置,但地图本身并没有在下方更新。 相反,我看到我的图钉位于灰色/空白地图背景上......直到我向任何方向轻推地图,无论多么轻微。 然后地图就显示出来了! (如果我只是在前一个图钉位置的一小段距离内移动,我通常会看到地图的任何部分已经加载。)

我怀疑我在这里做了一些愚蠢的事情,但我无法弄清楚什么,至少不是从 MapKit 文档中。 也许我使用了错误的电话? (嗯,我确实需要至少设置一次区域,是吗?尽管移动它似乎没有帮助。)我也尝试过使用 setCenterCooperative:animated: - 同样的问题。

我现在什么都不假设(没有双关语的意思)。 只是想找到我的路。

欢迎提供线索/赞赏!

更新:在遍历列表时,第一次调用 setRegion:animated:regionThatFits: ,然后调用 setCenterCooperative:animated: ,没有任何效果。 但有趣的发现是:如果我在这两种情况下将动画更改为“否”,地图就会更新! 仅当其设置为 YES 时。 (发生了什么事?!是动画:坏了?那不可能......???)

Greetings! I'm attempting to use MKMapView without any Apple code samples, though there are a few others out there of varying clarity. (I know, "Read the friendly manual." I've done that but it's not 100% clear, so please bear with me on this one.)

Here's the situation. I have a MKMapView object, wherein I have added a set of about ten MKPinAnnotation objects. So far, so good. Everything is alloced/released sanely and there doesn't appear to be any complaints from Instruments.

Upon initial display, I set up a MKCoordinateRegion object with the centerpoint at our first pin location, and a (arbitrary) span of 0.2 x 0.2. I then call:

[mapView setRegion:region animated:YES];
[mapView regionThatFits:region];

Wow! That worked well.

Meanwhile ... I also have a segmented control to allow for movement to each pin location. So as I tap through the list, the map animates to each new pin location with a new pair of calls to setRegion:animated: and regionThatFits: ... or at least that's the idea.

While the map does "travel" to the new pin location, the map itself doesn't update underneath. Instead, I see my pin on a gray/blank-map background ... until I nudge the map in any direction, however slightly. Then the map shows through! (If I'm only moving within a short distance of the previous pin location, I'll usually see whatever part of the map was already loaded.)

I suspect I'm doing something dumb here, but I haven't been able to figure out what, at least not from the MapKit docs. Perhaps I'm using the wrong calls? (Well, I do need to set the region at least once, yes? Moving that around doesn't seem to help though.) I have also tried using setCenterCoordinate:animated: - same problem.

I'm assuming nothing at this point (no pun intended). Just trying to find my way.

Clues welcome/appreciated!

UPDATE: Calling setRegion:animated: and regionThatFits: the first time, followed by setCenterCoordinate:animated: while traversing the list, has no effect. Interesting finding though: If I change animated to NO in both cases, the map updates!!! Only when it's set to YES. (Wha happen?! Is animated: broken? That can't be ... ???)

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

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

发布评论

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

评论(4

淑女气质 2024-08-01 22:45:56

事实证明,使用模拟器时地图更新不起作用。 当我在设备上尝试 setCenterCooperative:animated: 时,我确实得到了下面的地图更新。

底线:我相信模拟器在地图更新行为方面能够与设备相匹配。 唉,我错了! 学过的知识。 “不要让这种事发生在你身上。” :)

It turns out that the map update doesn't work when using the SIMULATOR. When I try setCenterCoordinate:animated: on the device, I do get the map update underneath.

Bottom line: I was trusting the simulator to match the device in terms of map updating behavior. Alas, I was mistaken! Lesson learned. "Don't let this happen to you." :)

不…忘初心 2024-08-01 22:45:56

您需要在主线程上下文中调用 setRegion:animated: 调用。
只需执行以下操作:

....
[self performSelectorOnMainThread:@selector(updateMyMap) withObject:nil waitUntilDone:NO];

}

-(void) updateMyMap {
    [myMap setRegion:myRegion animated:YES];    
}

它应该在任何情况下都可以工作(无论是否有动画),并且地图会在下面更新。

You need to invoke the setRegion:animated: call in the Main thread context.
Just do something like:

....
[self performSelectorOnMainThread:@selector(updateMyMap) withObject:nil waitUntilDone:NO];

}

-(void) updateMyMap {
    [myMap setRegion:myRegion animated:YES];    
}

and it should work in any case (animated or not), with the map updated underneath.

浅浅淡淡 2024-08-01 22:45:56

嗯奇怪。 即使在模拟器中,地图也会在我的 Mac 上更新。 也许网络设置(代理或其他)会阻止地图小部件在模拟器上下载图块?

Hum strange. The map updates on my Mac even in the simulator. Maybe a network setting (proxy or whatever) that would prevent the map widget to download the tiles on the simulator ?

迷途知返 2024-08-01 22:45:56

尽管这是一个老话题,但我想我应该谈谈我的经验。 看来地图动画仅在运行 iOS 3.1.x 的设备和运行 3.1.x 的模拟器上失败。 如果动画打开,我的 3.1.3 开发版 iPod touch 无法缩放。

Even though this is an old topic I thought I'd ring in with my experience. It seems the map animation only fails on devices running iOS 3.1.x and the simulator running 3.1.x. My dev iPod touch with 3.1.3 fails to zoom if animation is on.

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