I encountered this problem today. It turns out that when using spin
, the other things that are running in main thread run first. That means, if you have
let progressIndicator //
progressIndicator.startAnimation(self)
// do tasks
progressIndicator.stopAnimation(self)
The order in reality is
let progressIndicator //
// do tasks
progressIndicator.startAnimation(self)
progressIndicator.stopAnimation(self)
So you never see the animation. Here is the workaround, stop main runloop a little while, after progressIndicator.startAnimation(self)
.
let progressIndicator //
progressIndicator.startAnimation(self)
RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.001))
// do tasks
progressIndicator.stopAnimation(self)
Then everything will be fine. I find this answer here. You can also try other answers there too.