我試圖用三種不同的顏色每30秒更改UIview的背景顏色,直到條件失敗(while循環)。以下是我的代碼。它工作正常,但造成延遲。用三種顏色每30秒更改視圖顏色
斯威夫特3:
DispatchQueue.global(qos: .background).async {
while x < y {
DispatchQueue.main.async() {
self.view.backgroundColor = UIColor(hexString:hexValue[self.currentColorIndex!])
}
Thread.sleep(forTimeInterval: 30.0)
}
}
不要把你的應用程序睡覺 –