Ios UIView动画召回将快速进行

Ios UIView动画召回将快速进行,ios,objective-c,animation,uiview,Ios,Objective C,Animation,Uiview,我有一个ui按钮,当我单击该按钮时,它将调用动画方法。但当我再次单击时,动画将变得奇怪,它将快速移动。单击按钮时如何重建动画?谢谢 我尝试了[self.view.layer removeAllAnimations],但不起作用 这是我的钮扣 - (void)viewDidLoad { ... [_go_button addTarget:self action:@selector(animation_go:) forControlEvents:UIControlEventTouchUp

我有一个
ui按钮
,当我单击该按钮时,它将调用动画方法。但当我再次单击时,动画将变得奇怪,它将快速移动。单击按钮时如何重建动画?谢谢

我尝试了
[self.view.layer removeAllAnimations]
,但不起作用

这是我的钮扣

- (void)viewDidLoad {
   ...
   [_go_button addTarget:self action:@selector(animation_go:) forControlEvents:UIControlEventTouchUpInside];
   ...
}
这是
animation\u go:
方法

- (void)animation_go:(id)sender
{
   ...
   for (int start = 0; start < end; start++) {
      // that will create four uiview and add to self.view
   }
   _thread = [[NSThread alloc] initWithTarget:self selector:@selector(animation) object:nil];
   [_thread start];
}
- (void)animation
{
    [UIView beginAnimations:@"Move randomly" context:nil];
    [UIView setAnimationDuration:0.06];

    CGPoint squarePostion1 = [self return_point:_first_view add_view:_add_first_view tag:1];
    _add_first_view.center = squarePostion1;

    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animation)];
    [UIView commitAnimations];
}

改为使用CABASICIATION:

CABasicAnimation* translationAnimation;
translationAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
translationAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(266, 266)];
translationAnimation.duration = 1;
translationAnimation.cumulative = YES;
translationAnimation.repeatCount = HUGE_VALF;
translationAnimation.removedOnCompletion = NO;
translationAnimation.fillMode = kCAFillModeForwards;
[self.label.layer addAnimation:translationAnimation forKey:@"positionAnimation"];
此代码为层特性提供了基本的单关键帧动画功能。您还可以根据苹果的技术说明实现暂停/开始层动画功能


您是指[self.view.layer removeAllAnimations]吗?这是我的错,谢谢。请澄清您想要达到什么样的效果?通过在动画打开时单击按钮,动画应该停止并从初始状态开始?这只是简单的翻译动画?是的。我希望动画成为初始状态。谢谢~!!你的榜样是伟大的。