我使用for循环动态创建了3个视图,在其中调用了以下方法进行旋转动画。
- (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];
}
请帮助我...