14

我有 3 个使用 for 循环动态创建的视图。在那我调用了下面的旋转动画方法

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

请帮我...

4

1 回答 1

31

这可能是因为您正在从另一层移除动画,而不是从添加动画的同一层移除动画。(您使用了错误的视图来移除动画,请再次检查)。

您可以使用它从 yourView 中删除动画:

[yourView.layer removeAllAnimations];
于 2013-05-02T12:23:13.477 回答