如何停止的UIView CABasicAnimation在iPhone(How to stop UI

2019-09-01 18:10发布

我通过使用循环动态创建的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];
}

请帮我...

Answer 1:

这可能是因为你是从其他层去除动画,而不是从你上添加了动画同一层删除动画。 (您使用了错误的观点删除动画,请检查一遍)。

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

[yourView.layer removeAllAnimations];


文章来源: How to stop UIView CABasicAnimation in iPhone