在旋转期间MKMapView的centerCoordinate的错误? [英] Bug with MKMapView's centerCoordinate during rotation?

查看:89
本文介绍了在旋转期间MKMapView的centerCoordinate的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我可能在 MKMapView 中发现了一个错误,但是我想让人们运行它,看看是否有其他人遇到过这个问题。我正在使用iOS 7和Xcode 5.

I think I may have found a bug in MKMapView, but I'd like to run it by folks to see if anyone else has run into this issue. I'm using iOS 7 and Xcode 5.

在我的故事板中,我有一个带 MKMapView的视图控制器在里面。我的应用程序允许旋转纵向和横向。当用户旋转设备时,我使用autolayout来保持 MKMapView 的框架。

In my storyboard, I have a view controller with an MKMapView in it. My app allows rotation to both portrait and landscape. I am using autolayout to keep the frame of the MKMapView updated when the user rotates the device.

轮换后,似乎 MKMapView regionDidChangeAnimated centerCoordinate >委托方法:

After rotation, it appears that MKMapView is reporting an incorrect centerCoordinate in the regionDidChangeAnimated delegate method:

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
    NSLog(@"%@ %@", @(mapView.centerCoordinate.latitude), @(mapView.centerCoordinate.longitude));
}

当我的视图控制器首次以纵向方向加载时,我得到以下输出:

When my view controller first loads in portrait orientation, I get the following output:

25.69266565483518 -40               
37.17818069458006 -96.05458068847656

将设备旋转到横向后,我得到以下输出:

After I rotate the device to landscape orientation, I get the following output:

9.656197790830817 -96.05458068847656

将设备旋转回纵向后,我得到以下输出:

After I rotate the device back to portrait orientation, I get the following output:

37.17818069458006 -96.05458068847656

最后,这里是纵向和横向的截图。我在图像的中心画了点,表明 - 至少从渲染的角度来看 - 中心是相同的。

Finally, here are screenshots of both portrait and landscape orientations. I drew dots over the center of the images to show that--at least from a rendering perspective--the centers are the same.


这实际上是一个错误,因为它出现或我遗失了什么?

Is this actually a bug as it appears or am I missing something?

编辑:

我更改了 regionDidChangeAnimated 中的代码,以便 centerCoordinate 在延迟一毫秒后输出。当我这样做时,我得到了正确的结果。但是,这不是最优的,我仍然认为 centerCoordinate 应该在 MKMapView 之前更新 > regionDidChangeAnimated 被调用。

I changed the code in regionDidChangeAnimated so that the centerCoordinate is outputted after a one millisecond delay. When I do this, I get correct results. However, this is not optimal and I still think that centerCoordinate should be updated by MKMapView before regionDidChangeAnimated is called.

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_MSEC), dispatch_get_main_queue(), ^
    {
        NSLog(@"%@ %@", @(mapView.centerCoordinate.latitude), @(mapView.centerCoordinate.longitude));
    });
}

37.17818069458006 -96.05458068847656
37.17818069458006 -96.05458068847656
37.17818069458006 -96.05458068847656
37.17818069458006 -96.05458068847656

编辑:

我创建了一个示例项目,以便重现Apple bug报告的错误。我注意到,如果MKMapView未嵌入导航控制器中,则centerCoordinate属性始终报告正确的值。只要我将其嵌入导航控制器中 - 并关闭在顶部条形和底部条形下延伸边缘选项 - 它就会报告错误的值。

I created a sample project in order to reproduce the bug for an Apple bug report. What I noticed that if the MKMapView is not embedded within a navigation controller, the centerCoordinate property always reports the correct value. As soon as I embedded it within a navigation controller--and turned off the "extend edges under top bars and bottom bars" options--it reported incorrect values.

推荐答案

我提交给Apple的缺陷被确认为重复。看起来这确实是MapKit中的一个错误。

The defect I submitted to Apple was confirmed to be a duplicate. Looks like this is, indeed, a bug in MapKit.

这篇关于在旋转期间MKMapView的centerCoordinate的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆