0

私のコードは以下のとおりです、

int i;
for (i=1; i < 13; i++ ){
    UIButton * myButton1 = (UIButton *)([self.view viewWithTag:i]);
    NSString *imageLoop2=[NSString stringWithFormat:@"%@",[arr1 objectAtIndex:i-1]];

    [UIView beginAnimations:@"Flip" context:NULL];
    [UIView setAnimationDuration:0.60];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:myButton1 cache:NO];
    myButton1.userInteractionEnabled = NO;
    myButton1.alpha=1.0f;
    [myButton1 setBackgroundImage:[UIImage imageNamed:imageLoop2] forState:UIControlStateNormal];

    [UIView commitAnimations];

}

同じ時間内にすべてのボタンを反転します。
しかし、私の問題は、「最初のボタンが完全にフリップアニメーションになり、次に2番目のボタンがフリップを開始する」という男性が1人ずつフリップすることです。

提案をお願いします。

ありがとう

4

4 に答える 4

1

imageIndex++はグローバルにどこかにあります。

self.view.userInteractionEnabled =NO;

imageIndex++;
if (imageIndex == 13){
    self.view.userInteractionEnabled =YES;
    imageIndex=0;
    return;
}

 UIButton * myButton1 = (UIButton *)([self.view viewWithTag:imageIndex]);
[UIView beginAnimations:@"Flip" context:NULL];
[UIView setAnimationDuration:0.40];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:myButton1 cache:NO];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(stopButton)];


 NSString *imageLoop2 = [NSString stringWithFormat:@"%@",[arr1 objectAtIndex:imageIndex-1]];
 myButton1.userInteractionEnabled = NO;
 myButton1.alpha=1.0f;
 [myButton1 setBackgroundImage:[UIImage imageNamed:imageLoop2] forState:UIControlStateNormal];

 [UIView commitAnimations]; 
于 2011-08-30T04:10:42.780 に答える
1

これを試して。iグローバルにどこかで宣言します。

i = 0;
[self flipNextButton];

このようにflipNextButtonメソッドを定義します。

- (void)flipNextButton {

    i++;
    if (i == 13) return;

    [UIView beginAnimations:@"Flip" context:NULL];
    [UIView setAnimationDuration:0.60];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:myButton1 cache:NO];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(flipNextButton);

    UIButton * myButton1 = (UIButton *)([self.view viewWithTag:i]);
    NSString *imageLoop2 = [NSString stringWithFormat:@"%@",[arr1 objectAtIndex:i-1]];
    myButton1.userInteractionEnabled = NO;
    myButton1.alpha=1.0f;
    [myButton1 setBackgroundImage:[UIImage imageNamed:imageLoop2] forState:UIControlStateNormal];

    [UIView commitAnimations];
}
于 2011-08-29T09:15:08.447 に答える
1

同じブロックで次々にアニメーションを実行します。試してみてください[UIView setAnimationDelay:delay];

また、2ブロックまたは1ブロックのアニメーションはバックグラウンドスレッドで実行されることに注意してください。したがって、この変更により-

int i;
[UIView beginAnimations:@"Flip" context:NULL];
[UIView setAnimationDelegate:self];
float delay = 0;
float duration = 0.6;

for (i=1; i < 13; i++ ){
    UIButton * myButton1 = (UIButton *)([self.view viewWithTag:i]);
    NSString *imageLoop2 = [NSString stringWithFormat:@"%@",[arr1 objectAtIndex:i-1]];

    [UIView setAnimationDelay:delay];
    [UIView setAnimationDuration:duration];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:myButton1 cache:NO];
    myButton1.userInteractionEnabled = NO;
    myButton1.alpha=1.0f;
    [myButton1 setBackgroundImage:[UIImage imageNamed:imageLoop2] forState:UIControlStateNormal];
    delay = delay + duration;

}
[UIView commitAnimations];

また、Apple Docsによると、シングルブロックアニメーションは、実行している2ブロックアニメーションと比較して、パフォーマンスの点でよりスムーズです。ちょっとした考え...

于 2011-08-29T09:18:13.473 に答える
0
int i;
[UIView beginAnimations:@"Flip" context:NULL];
[UIView setAnimationDelegate:self];
float delay = 0;
float duration = 0.6;

for (i=1; i < 13; i++ ){
    UIButton * myButton1 = (UIButton *)([self.view viewWithTag:i]);
    NSString *imageLoop2 = [NSString stringWithFormat:@"%@",[arr1 objectAtIndex:i-1]];

    [UIView setAnimationDelay:delay];
    [UIView setAnimationDuration:duration];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:myButton1 cache:NO];
    myButton1.userInteractionEnabled = NO;
    myButton1.alpha=1.0f;
    [myButton1 setBackgroundImage:[UIImage imageNamed:imageLoop2] forState:UIControlStateNormal];
    delay = delay + duration;

}
[UIView commitAnimations];
于 2013-04-16T08:49:09.247 に答える