多个regionDidChangeAnimated调用-什么给出了?

发布于 2024-08-18 00:33:35 字数 580 浏览 3 评论 0原文

我在 UITableView 中有一个 MKMapView 作为自定义单元格(不要问;) - 不知道它是否真的重要),为此我注册了一个 RegionDidChangeAnimated 委托方法。当 UITableView 加载时,此方法会被调用三次 - 一次使用实际区域,然后再使用两次远离的区域。在模拟器中,我始终得到一个中心区域(+37.43997405,-97.03125000)。在设备上,它似乎取决于位置管理器报告的位置,该位置管理器初始化地图视图。

为什么我收到三个regionDidChangeAnimated 调用?为什么最后两个的中心坐标偏离了?

这是我用来获取中心坐标的代码:

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
    CLLocation *l = [[CLLocation alloc] initWithLatitude:self.mapView.centerCoordinate.latitude longitude:self.mapView.centerCoordinate.longitude];
(....)

I have a MKMapView inside a UITableView as a custom cell (don't ask ;) - don't know if it matters really), for which I register a regionDidChangeAnimated delegate method. This method gets called three times when the UITableView is loaded - once with the actual region and then two more times with a region that is way off. In the simulator, I consistently get a region with center (+37.43997405, -97.03125000). On the device, it seems to depend on the location reported by the location manager, which initializes the map view.

Why am I getting three regionDidChangeAnimated calls? And why are the center coordinates for the last two of them off?

This is the code I use to get the center coordinates:

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
    CLLocation *l = [[CLLocation alloc] initWithLatitude:self.mapView.centerCoordinate.latitude longitude:self.mapView.centerCoordinate.longitude];
(....)

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

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

发布评论

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

评论(1

他是夢罘是命 2024-08-25 00:33:35

我已经在自定义表格视图单元格内设置了地图视图,并将该单元格添加到表格视图中(尽管地图视图在何处/如何显示绝对不重要)。

我没有看到任何对 regionDidChangeAnimated: 委托方法的意外调用。

仅当出现以下情况时,我才会看到对此方法的调用:

  1. 用户更改地图的位置/缩放,或者
  2. 某些代码更改地图的中心/跨度

您确定看到了意外调用吗?您没有使用代码来设置地图的区域(中心/跨度)?

I have set up a map view inside a custom table view cell and added that cell to a table view (although it definitely should not matter where/how the map view is displayed).

I do not see any unexpected calls to the regionDidChangeAnimated: delegate method.

I see calls to this method only when:

  1. The user changes the position/zoom of the map, OR
  2. Some code changes the center/span of the map

Are you sure that you are seeing unexpected calls? You are not using code to setup the region (center/span) of the map?

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