2013-05-02 15 views
11

Ich habe 3 Ansichten dynamisch erstellt mit For-Schleife. dass ich rief die unten Methode zur Rotation AnimationSo stoppen Sie UIView CABasicAnimation in iPhone

- (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"]; 
} 

wie kann ich die Rotation Animation in Berührung Blick beginnen stoppen? ... i die folgende Codierung in Berührung beginnt Methode versucht, aber es nicht

funktionierte
-(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]; 
} 

mir bitte helfen ...

+1

möglich Duplikat (http://stackoverflow.com/questions/2306870/is-there -eine-weg-zu-pause-a-cabicasanimation) – Pfitz

Antwort

23

Es kann sein, wegen dir Animation von der anderen Schicht entfernt werden, anstatt Animation aus der gleichen Schicht entfernen Sie Animation hinzugefügt. (Sie verwenden die falsche Ansicht, um die Animation zu entfernen, überprüfen Sie sie bitte erneut).

können Sie diese Animation von yourView entfernen verwenden: [? Gibt es eine Möglichkeit, eine CABasicAnimation zu pausieren]

[yourView.layer removeAllAnimations];