私はクイズゲームを作成していますが、3秒間隔で1つずつ消えるUIButtonsを実装する最良の方法を理解できません。 3秒後に最初のUIButtonが消えますが、その後のUIButtonはかなり長くなります。iPhone How To:設定間隔で一気に消えるUIButton
私が問題になるのは、自分のコードが消滅する各UIButtonで非効率になるということです。次のメソッドは、繰り返しのNSIntervalを呼び出して、後続の各UIButtonを消滅させるものです。
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;
}
}
}
を。ありがとう –