簡體   English   中英

如何在iPhone中停止UIView CABasicAnimation

[英]How to stop UIView CABasicAnimation in iPhone

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

我如何才能停止觸摸動畫中的旋轉動畫?...我嘗試了下面的編碼中的觸摸begin方法,但是沒有用

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

請幫我...

可能是因為您要從另一層刪除動畫,而不是要從添加動畫的同一層刪除動畫。 (您使用錯誤的視圖刪除了動畫,請再次檢查它)。

您可以使用它從yourView中刪除動畫:

[yourView.layer removeAllAnimations];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM