Je crée un jeu-questionnaire et je ne peux pas comprendre la meilleure façon d'implémenter les UIButtons qui disparaissent un par un à 3 secondes d'intervalle. Je peux faire disparaître le premier UIButton au bout de 3 secondes, mais les UIButtons suivants prennent beaucoup plus de temps.iPhone Comment: UIButtons qui disparaissent un par un à l'intervalle défini
Je crois que le problème est que mon code devient plus inefficace avec chaque UIButton que je fais disparaître. La méthode suivante est ce que j'appelle avec un NSInterval répétitif pour faire disparaître chaque UIButton suivante:
- (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;
}
}
}
Cela a très bien fonctionné. Merci –