UIView two animations coexisting

cocoa-touch, ios, iphone, objective-c, xcode

Solution

You will not be able to do this with the block-based animations as you have them here. You will need to split your animations up using explicit animations with `CABasicAnimation`. Create one animation for the pulsating effect and set it to repeat indefinitely. Then you can move it around by setting the center (either animated or non-animated).

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"];

As soon as you add the animation to the layer, it will begin animating. To remove the animation, simply call `[self.layer removeAnimationForKey:@"pulse"` or `removeAllAnimations:`.

Problem

How can I have one animation continue forever after calling a second animation? For example: 1) start an object pulsating 2) Move it while its pulsating 3) it continues pulsating Everything works except the second animation is stopping the first one indefinitely. Below is some sample code: ``` //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){ }]; ```

Original source