当语音合成器正在读取文本 block 时,我试图以 5.0 的增量推进确定的进度条。这是我的代码(不起作用):
if speechSynthesizer.speaking == false {
if let contents = textView.string where !contents.isEmpty {
speechSynthesizer.startSpeakingString(contents)
progressIndicator.hidden = false
while speechSynthesizer.speaking == true {
progressIndicator.incrementBy(5.0)
}
} else {
speechSynthesizer.startSpeakingString("The document is empty.")
}
}
}
进度条显示但不增加。如果我取出“while...”并仅使用语句“progressIndicator.incrementBy(5.0)”,则进度会增加,但只会增加一次。
关于如何解决这个问题有什么建议吗?
提前感谢大家!
-同步-
最佳答案
您可能需要将更新 UI 的代码移至主运行循环,以便 UI 真正得到更新。因此,将该行放在调度 block 内。
dispatch_async(dispatch_get_main_queue()) {
//insert UI code here
}
关于swift - 使用 Swift 2.0 (OS X) 在语音合成过程中推进进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35249338/