2012-02-22 27 views
0

私のコードでは、else部分の前の部分をアニメーション化したいが、else節の中に入れる。 if else節の最初の部分は、関数が最初に呼び出されたときに実行され、その部分の内部にはアニメーションの途中にある1秒後に関数を呼び出すタイマーセットがありますが、この最後の部分は必要ありません私はちょうどそれが即座に起こることを望んでいます。アニメーション期間の途中でUIViewの途中で特定のオブジェクトのアニメーションを停止する

-(void)performAnimationToRight 
{ 
if (!timer){ 

[UIView beginAnimations:@"Move" context:nil]; 
[UIView setAnimationDuration:2]; 
[UIView setAnimationBeginsFromCurrentState:YES]; 


card0.center = CGPointMake(card0.center.x+388, card0.center.y); 
card1.center = CGPointMake(card1.center.x+388, card1.center.y); 
card2.center = CGPointMake(card2.center.x+388, card2.center.y); 


[UIView commitAnimations]; 

timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(performAnimationToRight) userInfo:nil repeats:NO]; 


}else{ 

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

timer = nil; 

} 

} 

この部分のアニメーションが表示されないようにするにはどうすればよいですか。

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

ありがとう。

答えて

0

ブロックの使用はどうですか?

[UIView animateWithDuration:2 animations:^{ 

    card0.center = CGPointMake(card0.center.x+388, card0.center.y); 
    card1.center = CGPointMake(card1.center.x+388, card1.center.y); 
    card2.center = CGPointMake(card2.center.x+388, card2.center.y); 
} 
completion:^(BOOL finished) { 

    card2.frame = CGRectMake(-330,card2.frame.origin.y, card2.frame.size.width, card2.frame.size.height); 
}]; 
関連する問題