swift - iOS 13.2 从 MapKit 中删除叠加层导致 map 闪烁

标签 swift mapkit overlay ios13

我在我的应用程序中使用 mapKit,我有几个函数可以使用叠加层渲染图形。
现在,随着 iOS 13.2 更新,当我移动 map (使用任何方法)时,删除单个叠加层并在 map 移动时重绘叠加层的函数 - 导致 map 中的所有图形闪烁 - 就好像它们都被重绘一样。
移动 map 的方法之一是 locationManager 的“didUpdateLocations”。

我不能发布代码,因为代码被分成了这么多子函数,所有子函数都以不同的组合调用。
但是我已经测试了许多方法来验证图形是否仅通过添加或删除叠加层的单个操作就闪烁。我已经评估了添加或删除的叠加层,以验证它只是一个小图形(MKPolyline)——而不是 map 上的一组图形/叠加层。

所以基本上,addOverlay 函数似乎有问题 - 重绘所有叠加层..,或类似的东西......

还有其他人在 iOS13.2 上遇到过这个问题吗?

最佳答案

类似的事情正在发生在我身上。我有一个应用程序几个月没有改变,但是当我升级到 iOS 13.2 时,它开始出现异常。该应用程序具有呈现 MKTileOverlays 的 mapView。围绕中心蓝点的 2x2 瓷砖网格在所有缩放级别以每秒一次的速率连续闪烁。我能够在屏幕闪烁时(在 iPhone 上)捕获它,我可以看到它在更高的缩放级别显示了许多图块。
在下图中, map 的缩放级别为 14。我用绿色勾勒出 2x2 闪烁的图块。当它闪烁时,会出现几个缩放级别为 16(橙色轮廓)和缩放级别 17(紫色轮廓)的图块。
只有当我之前在这些区域中放大到该级别时,才会出现更高缩放级别的图块。否则,2x2 闪烁网格为空。
enter image description here
更新:
这是我在 2019 年 12 月 5 日从 Apple 开发人员技术支持收到的回复......

What you’re seeing is a known bug in MapKit. I wanted to pass along some additional information to help reduce how often you may see this in your real app. A common pattern that some apps use in the MKMapView usage is to do frequent updates to their overlays, such as removing all overlays at once, and then adding some subset (or all) of them back. In particular, if this is done to the hot code paths for user driven events, such as pinching and zooming the map, the blinking tile behavior is exacerbated.

In the case of the sample [provided by P. Stern], this is the location manager’s location update, which can be called at 60 Hertz in some circumstances. You can do something like a distance comparison and only update the polyline if there’s a significant enough change in the coordinate since the last time you replaced the polyline to be meaningful to the user for your trail use case. Applying this to your real app, please audit the points where you add and remove overlays, and try to reduce the number of times those methods get called. This won’t eliminate the tile blinking problem, but may reduce its frequency as a way to mitigate the effects of our issue.

When looking at your overlays, also consider why you need to add and remove overlays from the map, and if there are opportunities to do so in bulk, but rarely. Another common pattern I see often is trying to keep track of the overlays to keep memory usage down, and continually updating the overlays added to the map to reflect only those relevant to the user’s location or visible map rectangle. However, the MKOverlay objects themselves are usually not large, because they are only a coordinate and a bit of data, so the memory saved by these techniques is often in the kilobyte to low megabyte range, which isn’t much improvement when an app with a map needs 100 MB just for the map, let alone the rest of the app’s data and view controllers.


最终更新:
苹果似乎已经解决了这个问题。我正在使用 iOS 13.7 (Xcode 12) 并且不再发生闪烁。正如 Zifigo 指出的那样,它可能已在 iOS 13.4 中修复。

关于swift - iOS 13.2 从 MapKit 中删除叠加层导致 map 闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58674817/

相关文章:

ios - 将注释链接到模型数组

Android Yandex mapkit 路线

html - 文本叠加隐藏在旁边的图像后面

google-maps - 如何获取您的图像 URL 磁贴? (谷歌地图)

swift - 以编程方式切换 MKUserTrackingBarButtonItem

ios - 检查 UITextFields 集合中的文本字段是否为空

objective-c - 转换 Base64 GZipped 字符串 Objective-c 或 Swift

ios - Swift 4.2 语法更改 - Swift 类型推断发生了什么?

swift - 计算有多少自定义注释被添加到 mapView swift 4

javascript - 如何在单击按钮时设置 Vaadin 8 LoadingIndicatorConfiguration