I have 3 views dynamically created by using for loop. in that i called the below method for rotation animation
- (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"];
}
how can i stop the rotation animation in touch begin of view?... i tried the below coding in touch begin method but it didn't work
-(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];
}
please help me...
It may be because of you are removing animation from the other layer rather than to remove animation from the same layer you added animation on. (You are using the wrong view to remove animation, please check it again).
You can use this to remove animation from yourView:
[yourView.layer removeAllAnimations];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With