2012-03-17 7 views
3

私はそれを止めるまで繰り返す必要があるアニメーションを持っています。iOS - 繰返しUIAnimationを停止しますか?

ボタンをクリックした後でアニメーションを停止するにはどうすればよいですか?

+3

[UIView animateWithDurationを繰り返すハンドラを持つ方法](http://stackoverflow.com/questions/6766955/how-to-have-a-handler-to-repeat-uiview-animatewithduration) ) – sch

答えて

2

Uでは代わりにCABasicAnimationを使用できます。 uはそれを停止したいとき

CABasicAnimation *appDeleteShakeAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; 
appDeleteShakeAnimation.autoreverses = YES; 
appDeleteShakeAnimation.repeatDuration = HUGE_VALF; 
appDeleteShakeAnimation.duration = 0.2; 
appDeleteShakeAnimation.fromValue = [NSNumber numberWithFloat:-degreeToRadian(5)]; 
appDeleteShakeAnimation.toValue=[NSNumber numberWithFloat:degreeToRadian(5)]; 
[self.layer addAnimation:appDeleteShakeAnimation forKey:@"appDeleteShakeAnimation"]; 

次に、あなただけの

あなたはこれを試してみてください...あなたは一つの他のオプションUIViewAnimationOptionAllowUserInteractionを追加する必要が

[self.layer removeAnimationForKey:@"appDeleteShakeAnimation"]; 
12

呼び出すことができます。

[UIView animateWithDuration:2 delay:0 options:UIViewAnimationCurveLinear | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction animations:^ 
{ 
    view.frame = CGRectMake(0, 100, 200, 200); 
} completion:^(BOOL finished) 
{ 
    if(! finished) return; 
}]; 

アニメーションを停止するには、

[view.layer removeAllAnimations]; 
+1

具体的な質問に対する優れた回答。アニメーション表示のための別のアプローチを示唆するものではありません。よくやった。 – SSemashko

+0

@Scarmysun:感謝のおかげで –

関連する問題