Reputation:
I have an NSProgressIndicator (spinning) that displays fine when it is not animating, but as soon as it starts animating it disappears. However, when I switch the style to a progress bar, it displays just fine, animations and all. Additionally, it reappears when it stops animating, so it is only invisible while it is spinning.
I am new to Cocoa programming, and I have been searching for several hours through my code and online trying to figure out my issue, but I have been unsuccessful. What would cause this issue?
My code is somewhat based on the code from Apple's sample AVSimplePlayer, found here.
Upvotes: 1
Views: 578
Reputation: 3355
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.
Upvotes: 1