swift - 延迟显示 UIMapView 直到 map 在 Swift 中完全加载

标签 swift ios8 mkmapview

在我的 Storyboard上,我设置了一个计时器(每 0.01 秒更新一次)和一个 UIMapView,它在加载 View Controller 时显示用户的位置。但是,当该屏幕加载时,计时器会滞后一点,直到 map 完全加载。我认为这是因为 map 的加载是在主线程上执行的阻塞函数。

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

最佳答案

可能不是。 map View 是一个 View 对象,而 View 对象不是线程安全的。

请注意,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。因此,您不太可能获得所需的准确性。

关于swift - 延迟显示 UIMapView 直到 map 在 Swift 中完全加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30714848/

相关文章:

ios - setBackButtonBackgroundImage 不工作

ios - UIScrollView 高度不根据 View 大小动态更新?

xcodebuild 无法从终端构建,但从 xcode 成功构建

ios - 从 MKMapView 中仅移除餐厅

iphone - 在 NSKVODallocateBreak 设置断点

ios - 使用索引在annotationView中显示文本数组

swift - 检查变量是否是可选的,以及它包装的类型

swift - 永久释放 MkMapView 的内存

iphone - Swift - 自定义键盘高度

ios - 您可以在 iOS 8 (w/Swift) 中以编程方式切换“请勿打扰”模式吗?