2013-05-02 6 views
11

forループを使用して3つのビューを動的に作成しました。その中で私はタッチで以下のコードは、メソッドを開始しようとした ...私はタッチで回転アニメーションを停止することができますどのようにiPhoneでUIView CABasicAnimationを停止する方法

- (void)runRightSpinAnimationOnView:(UIView*)view duration:(CGFloat)duration rotations: (CGFloat)rotations repeat:(float)repeat; 
{ 
    CABasicAnimation* rotationAnimation; 
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; 
    rotationAnimation.fromValue = [NSNumber numberWithFloat:0]; 
    rotationAnimation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)]; 
    //rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ]; 
    rotationAnimation.duration = duration; 
    //rotationAnimation.cumulative = YES; 
    rotationAnimation.repeatCount = repeat; 

[view.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"]; 
} 

は?ビューの開始回転アニメーションについては、以下のメソッドを呼び出したが、それは

を動作しませんでした
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *touch = [touches anyObject]; 
    int viewTag=[touch view].tag; 
    UIView *myView =(UIView *)[self.view viewWithTag:viewTag]; 
    [myView.layer removeAllAnimations]; 
} 

私を助けてください...

+1

が重複する可能性[をCABasicAnimationを一時停止する方法はありますか?](http://stackoverflow.com/questions/2306870/is-there -a-way-to-pause-a-cabasicanimation) – Pfitz

答えて

23

あなたが他の層からアニメーションを削除するのではなく、あなたが上でアニメーションを追加したのと同じ層からアニメーションを削除するのので、それがかもしれません。アニメーションを削除するには間違ったビューを使用しています。もう一度確認してください。

あなたはyourViewからアニメーションを削除するには、これを使用することができますの

[yourView.layer removeAllAnimations]; 
関連する問題