2012-02-21 19 views
0

カードが3枚あります。最初はすべてのカードが右に移動し、1秒後にカード2がビューの左側に表示され、さらに2番目のカード2が右側に移動します。私は次のコードを使ってこれを実装しました。ビューの負荷が、私は次のコードがある場合、ここでアニメーションを3ステップで1つずつ実行する

counter = 0; 
timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(performAnimationToRight) userInfo:nil repeats:YES]; 

がperformAnimationToRightMethod

の実装
-(void)performAnimationToRight 
{ 
if (counter == 0) { 

    CGAffineTransform transformToLeft = CGAffineTransformMakeTranslation(388,0); 

    [UIView beginAnimations:@"Move1" context:nil]; 
    [UIView setAnimationDuration:2]; 

    card0.transform = transformToLeft; 
    card1.transform = transformToLeft; 
    card2.transform = transformToLeft; 

    [UIView commitAnimations]; 

}else if(counter == 50){ 

    card2.frame = CGRectMake(-300,card2.frame.origin.y, card2.frame.size.width, card2.frame.size.height); 

}else if(counter == 200){ 

    timer = nil; 
    counter = 0; 
    CGAffineTransform transformToLeft = CGAffineTransformMakeTranslation(-300,0); 

    [UIView beginAnimations:@"Move2" context:nil]; 
    [UIView setAnimationDuration:2]; 

    card2.transform = transformToLeft; 

    [UIView commitAnimations]; 
} 

counter++; 
} 

ある問題は、最後のアクションカード2上の代わりに、左に右に移動に移動するということです私が使用して天気をかどうか、そしてそれは、

CGAffineTransform transformToLeft = CGAffineTransformMakeTranslation(-300,0); 

または

です

答えて

1

二つのコメント:

まず、あなたはそれが(おそらく)あなたの開始位置の左すべきフレーム原点だ設定することにより、counter == 50で左にあなたのカード2を移動しています。

第2に、CAKeyframeAnimationを使用して実装する方が簡単です。 NSTimercounterのメカニズムを管理する必要はありません。

関連する問題