延迟显示 UIMapView 直到地图完全加载 Swift

delay showing UIMapView until map fully loaded in Swift

在我的故事板上,我设置了一个计时器(每 0.01 秒更新一次)和一个在加载视图控制器时显示用户位置的 UIMapView。然而,当这个屏幕加载时,计时器会延迟一点,直到地图完全加载。我假设这是因为地图的加载是在主线程上执行的阻塞函数。

有没有办法在后台加载地图并在完全加载后显示地图,同时仍保持计时器 运行?

可能不会。地图视图是一个视图对象,视图对象不是线程安全的。

请注意 Apple 在 NSTimer 上的文档说:

A timer is not a real-time mechanism; it fires only when one of the run loop modes to which the timer has been added is running and able to check if the timer’s firing time has passed. Because of the various input sources a typical run loop manages, the effective resolution of the time interval for a timer is limited to on the order of 50-100 milliseconds.

50 毫秒是 0.02 秒。 100 毫秒是 0.04。因此,您不太可能获得所需的准确度。