UIView两个animation共存

调用第二个animation之后,如何让一个animation永远持续下去? 例如:

1)启动一个物体脉动2)移动它的脉动3)它继续脉动

除了第二个animation之外,所有的东西都是无止境的停止第一个animation。 以下是一些示例代码:

//Pulsate ** [UIView animateWithDuration:0.25 delay:0 options: (UIViewAnimationCurveEaseOut | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionRepeat) animations:^{ CGAffineTransform currentTransform = self.transform; CGAffineTransform newTransform1 = CGAffineTransformScale(currentTransform, .95, .95); [self setTransform:newTransform1]; CGAffineTransform newTransform2 = CGAffineTransformScale(currentTransform, 1, 1); [self setTransform:newTransform2]; } completion:nil]; //Move ** [UIView animateWithDuration:0.30 delay:0 options: (UIViewAnimationCurveEaseOut | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState ) animations:^{ [[(UIPinchGestureRecognizer*)sender view] setCenter:CGPointMake(myAppDelegate.MCViewReference.center.x-300, myAppDelegate.MCViewReference.center.y)]; } completion:^(BOOL finished){ }]; 

你将无法使用基于块的animation来做到这一点,就像你在这里所做的那样。 您将需要使用CABasicAnimation显式animation分割animation。 为脉动效果创build一个animation并将其设置为无限重复。 然后,您可以通过设置中心(animation或非animation)来移动它。

 CABasicAnimation *pulsation = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; pulsation.fromValue = [NSNumber numberWithFloat:0.95f]; pulsation.toValue = [NSNumber numberWithFloat:1.f]; pulsation.duration = 0.25f; pulsation.autoreverses = YES; pulsation.repeatCount = INFINITY; [self.layer addAnimation:pulsation forKey:@"pulse"]; 

只要将animation添加到图层,它就会开始animation。 要删除animation,只需调用[self.layer removeAnimationForKey:@"pulse"removeAllAnimations: [self.layer removeAnimationForKey:@"pulse"

您可以将animation分成不同的阶段,并使用完成块开始下一个阶段。