Activity 指标并不总是呈现

Activity indicator not always rendered

我有触发 activity 指标的代码:

activityIndicator.startAnimating()

触发后我会继续启动一些后台任务(例如转到服务器、获取数据、完成后回调)。

我遇到的问题是 activity 指示器的行为在某种意义上是不一致的,因为在 UI 上显示它有时 visible/gets 渲染和动画有时不(特别是如果应用程序在后台并返回到前台)

我不确定在继续启动后台任务之前调用 startAnimating() 时我需要做什么来确保它始终呈现在屏幕上。

任何指导将不胜感激。

谢谢。

我认为这是因为您可以在主线程之外使用 UI。尝试在

中包装代码
dispatch_async(dispatch_get_main_queue(), ^{
    // Your code to run on the main queue/thread
    self.activityIndicator.startAnimating()
});