MKMapView setRegion 不是常量

发布于 2024-10-03 06:04:15 字数 579 浏览 0 评论 0原文

我将 MKMapView 区域设置在 viewWillAppear: 内,以便地图在用户看到它时立即显示正确的区域:

[mapView setRegion:region animated:NO];

第一次这样做时,我会像这样修剪该区域:

alt text

然后从那里开始,当我设置完全相同的区域时,我得到如下内容:

alt text

第二个屏幕截图是我从一开始就想要得到的。我的猜测是我第一次设置区域时,地图视图未完全加载或类似的情况。有什么指示我应该做什么来解决这个问题吗?

编辑:这可能是相关的:在第一次调用 viewDidAppear 之前向 mapView 添加注释也不起作用。 pinView 只是不显示。如何确保地图视图已准备好在 viewWillAppear 中使用?

I'm setting my MKMapView region inside the viewWillAppear: so that the map displays the good region right as soon as the user sees it:

[mapView setRegion:region animated:NO];

The fist time I do it, I get the region trimmed like so:

alt text

Then from there on, when I set the exact same region, I get something like this:

alt text

The 2nd screenshot is what I want to get from the start. My guess is the first time I set the region, the mapview isn't fully loaded or something along these lines. Any pointer of what I should do to fix this?

EDIT: This is probably related: adding an annotation to the mapView before a first call to viewDidAppear is made isn't working either. The pinView just doesn't show up. How can I make sure the map view is ready to be used within viewWillAppear?

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

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

发布评论

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

评论(3

巨坚强 2024-10-10 06:04:15

前一段时间已经报告了有关 setRegion 方法的问题,我不知道从那时起它们是否已得到修复。查看 Apple 开发论坛上的以下帖子:

https://devforums.apple.com/message/ 57488

Issues have been reported regarding the setRegion method some time ago, I don't know if they've been fixed since then. Take a look at the following post on the Apple Dev Forums:

https://devforums.apple.com/message/57488

天气好吗我好吗 2024-10-10 06:04:15

我偶然发现这个线程建议向 setRegion: 调用添加延迟(如果您需要在 viewWillAppear 方法中调用它)。有点傻,但确实有效。

- (void)viewWillAppear:(BOOL)animated {
    [self performSelector:@selector(centerMap:) withObject:nil afterDelay:0.01];
}

我真的很好奇 mapView 缺少什么来在没有这种延迟的情况下进行正确的重新调整。

I stumbled upong this thread that suggested to add a delay to the setRegion: call (if you require to call it within the viewWillAppear method anyway). Kinda silly, but it works.

- (void)viewWillAppear:(BOOL)animated {
    [self performSelector:@selector(centerMap:) withObject:nil afterDelay:0.01];
}

I'm really curious as of what the mapView is missing to do the proper recentering without this delay.

盛夏已如深秋| 2024-10-10 06:04:15

Have you tried making the call from the MKMapViewDelegate mapViewDidFinishLoadingMap message? Perhaps this is late enough to get the region right?

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