我正在创建一个问答游戏,但我无法找出实现 UIButtons 的最佳方法,这些按钮会以 3 秒的间隔一个接一个地消失。我可以让第一个 UIButton 在 3 秒后消失,但随后的 UIButtons 需要更长的时间。
我相信问题是我的代码变得更加低效,我让每个 UIButton 消失。以下方法是我用重复的 NSInterval 调用的方法,以使每个后续 UIButton 消失:
-(void)hideButton { int buttonNum;
while(buttonNum != -1)
{
buttonNum = rand() % 5;
if(buttonNum != [quiz correctNumber])
{
if(buttonNum == 0 && [buttonOne isEnabled] == YES)
{
[UIView beginAnimations:@"buttonFades" context:nil];
[UIView setAnimationDuration:0.5];
[buttonOne setEnabled:NO];
[buttonOne setAlpha:0.0];
[UIView commitAnimations];
}
else if(buttonNum == 1 && [buttonTwo isEnabled] == YES)
{
[UIView beginAnimations:@"buttonFades" context:nil];
[UIView setAnimationDuration:0.5];
[buttonTwo setEnabled:NO];
[buttonTwo setAlpha:0.0];
[UIView commitAnimations];
}
else if(buttonNum == 2 && [buttonThree isEnabled] == YES)
{
[UIView beginAnimations:@"buttonFades" context:nil];
[UIView setAnimationDuration:0.5];
[buttonThree setEnabled:NO];
[buttonThree setAlpha:0.0];
[UIView commitAnimations];
}
else if(buttonNum == 3 && [buttonFour isEnabled] == YES)
{
[UIView beginAnimations:@"buttonFades" context:nil];
[UIView setAnimationDuration:0.5];
[buttonFour setEnabled:NO];
[buttonFour setAlpha:0.0];
[UIView commitAnimations];
}
else if(buttonNum == 4 && [buttonFive isEnabled] == YES)
{
[UIView beginAnimations:@"buttonFades" context:nil];
[UIView setAnimationDuration:0.5];
[buttonFive setEnabled:NO];
[buttonFive setAlpha:0.0];
[UIView commitAnimations];
}
buttonNum = -1;
}
}
}