我想连续动画多个按钮,但是当需要动画两次或多次动画时,代码根本不起作用。如何在swift 3中延迟多次动画对象?
//function that animates a button
func buttonAnimationChain(buttonColor:UIButton, iDelayTime: Int){
UIView.animate(withDuration: 0.5, delay: Double(iDelayTime), options: [],
animations: {
buttonColor.alpha = 0.0;
},
completion: {finished in
buttonColor.alpha = 1.0;
})
}
//function that displays the sequence
func showSequence(iGeneratedArraySequence: [Int]){
var iDelayTime:Int = 0;
for _ in 1 ... iGeneratedArraySequence.count{
if(iGeneratedArraySequence[iDelayTime] == 1){
buttonAnimationChain(buttonColor: buttonBlue, iDelayTime: iDelayTime);
}
if(iGeneratedArraySequence[iDelayTime] == 2){
buttonAnimationChain(buttonColor: buttonYellow, iDelayTime: iDelayTime);
}
if (iGeneratedArraySequence[iDelayTime] == 3){
buttonAnimationChain(buttonColor: buttonPurple, iDelayTime: iDelayTime);
}
if(iGeneratedArraySequence[iDelayTime] == 4){
buttonAnimationChain(buttonColor: buttonGreen, iDelayTime: iDelayTime);
}//end of if statement
iDelayTime += 1;
}//end of for loop
}//end of function
当产生的数组只有那些不重复的数字,动画作品完美,但一旦一个按钮,需要进行两次动画,什么也不显示。我认为这是因为按钮只是停留在非活动状态,即使另一个函数变成活动状态,我想不出一个解决方案来解决这个问题。我尝试过使用sleep()函数,但这只是产生不可思议的结果。
这个问题有点复杂。我需要按照一定的顺序对盒子进行动画处理,而不是使盒子来回闪烁。 –
@RyanYang请检查现在,请避免任何语法错误 –