我有一个 NSProgressIndicator (旋转),当它没有动画时显示良好,但一旦开始动画它就会消失。但是,当我将样式切换为进度条时,它显示得很好,包括动画等等。此外,当它停止动画时它会重新出现,因此它仅在旋转时不可见。
我是 Cocoa 编程的新手,我已经通过我的代码和在线搜索了几个小时,试图找出我的问题,但我没有成功。什么会导致这个问题?
我的代码在某种程度上基于Apple示例AVSimplePlayer的代码,发现here .
最佳答案
我今天遇到了这个问题。事实证明,当使用spin
时,主线程中运行的其他事情首先运行。这意味着,如果您有
let progressIndicator //
progressIndicator.startAnimation(self)
// do tasks
progressIndicator.stopAnimation(self)
实际的顺序是
let progressIndicator //
// do tasks
progressIndicator.startAnimation(self)
progressIndicator.stopAnimation(self)
所以你永远看不到动画。这是解决方法,在 progressIndicator.startAnimation(self)
之后停止主运行循环一会儿。
let progressIndicator //
progressIndicator.startAnimation(self)
RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.001))
// do tasks
progressIndicator.stopAnimation(self)
那么一切都会好起来的。我找到这个答案here 。您也可以在那里尝试其他答案。
关于macos - NSProgressIndicator 每当开始动画时就会消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19966590/