MKMapView setRegion 不是常量
我将 MKMapView 区域设置在 viewWillAppear: 内,以便地图在用户看到它时立即显示正确的区域:
[mapView setRegion:region animated:NO];
第一次这样做时,我会像这样修剪该区域:
然后从那里开始,当我设置完全相同的区域时,我得到如下内容:
第二个屏幕截图是我从一开始就想要得到的。我的猜测是我第一次设置区域时,地图视图未完全加载或类似的情况。有什么指示我应该做什么来解决这个问题吗?
编辑:这可能是相关的:在第一次调用 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:
Then from there on, when I set the exact same region, I get something like this:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
前一段时间已经报告了有关 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
我偶然发现这个线程建议向
setRegion:
调用添加延迟(如果您需要在 viewWillAppear 方法中调用它)。有点傻,但确实有效。我真的很好奇 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.I'm really curious as of what the mapView is missing to do the proper recentering without this delay.
您是否尝试过从 MKMapViewDelegate< 进行调用/a> mapViewDidFinishLoadingMap 消息?也许现在已经太晚了,无法让该地区恢复正常?
Have you tried making the call from the MKMapViewDelegate mapViewDidFinishLoadingMap message? Perhaps this is late enough to get the region right?