我有這樣的代碼,我想基本上是:更改按鈕圖像進行了一定的時間,然後重新設置,然後換另一個按鈕等等反正有沒有把它變成for循環或改進它?
buttonList[total[0]].setImage(imagePlay, forState: .Normal);
let time = dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW), Int64(speed * Double(NSEC_PER_SEC)))
dispatch_after(time, dispatch_get_main_queue()) {
self.buttonList[total[0]].setImage(self.og, forState: .Normal);
self.buttonList[total[1]].setImage(self.imagePlay, forState: .Normal);
let time = dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW), Int64(speed * Double(NSEC_PER_SEC)))
dispatch_after(time, dispatch_get_main_queue()) {
self.buttonList[total[1]].setImage(self.og, forState: .Normal);
self.buttonList[total[2]].setImage(self.imagePlay, forState: .Normal);
let time = dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW), Int64(speed * Double(NSEC_PER_SEC)))
dispatch_after(time, dispatch_get_main_queue()) {
self.buttonList[total[2]].setImage(self.og, forState: .Normal);
self.buttonList[total[3]].setImage(self.imagePlay, forState: .Normal);
let time = dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW), Int64(speed * Double(NSEC_PER_SEC)))
dispatch_after(time, dispatch_get_main_queue()) {
self.buttonList[total[3]].setImage(self.og, forState: .Normal);
self.buttonList[total[4]].setImage(self.imagePlay, forState: .Normal);
let time = dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW), Int64(speed * Double(NSEC_PER_SEC)))
dispatch_after(time, dispatch_get_main_queue()) {
self.buttonList[total[4]].setImage(self.og, forState: .Normal);
self.buttonList[total[5]].setImage(self.imagePlay, forState: .Normal);
let time = dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW), Int64(speed * Double(NSEC_PER_SEC)))
dispatch_after(time, dispatch_get_main_queue()) {
self.buttonList[total[5]].setImage(self.og, forState: .Normal);
self.buttonList[total[6]].setImage(self.imagePlay, forState: .Normal);
let time = dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW), Int64(speed * Double(NSEC_PER_SEC)))
dispatch_after(time, dispatch_get_main_queue()) {
self.buttonList[total[6]].setImage(self.og, forState: .Normal);
self.buttonList[total[7]].setImage(self.imagePlay, forState: .Normal);
let time = dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW), Int64(speed * Double(NSEC_PER_SEC)))
dispatch_after(time, dispatch_get_main_queue()) {
self.buttonList[total[7]].setImage(self.og, forState: .Normal);
self.buttonList[total[8]].setImage(self.imagePlay, forState: .Normal);
let time = dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW), Int64(speed * Double(NSEC_PER_SEC)))
dispatch_after(time, dispatch_get_main_queue()) {
self.buttonList[total[8]].setImage(self.og, forState: .Normal);
self.replayButton.enabled = true;
for(var i = 0; i < self.buttonList.count; i++){
self.buttonList[i].enabled = true;
正如你可以看到這是一個長期的過程最終我會有30 +的大小的數組,有人可以建議一個更好的方式嗎?謝謝。