I've got a explicit animation where I want to set the final value so that the object stays at the end point. But how I can achieve this on a delayed animation: Here's the code:
CAKeyframeAnimation *moveAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
moveAnimation.duration = 0.3;
moveAnimation.cumulative = YES;
moveAnimation.repeatCount = 1;
// Bounce
[moveAnimation setValues:[NSArray arrayWithObjects:
[NSValue valueWithCGPoint:[self getCoordinatePointForAnimationWithRadius:0 withIndex:i]],
[NSValue valueWithCGPoint:[self getCoordinatePointForAnimationWithRadius:radius + 10 withIndex:i]],
[NSValue valueWithCGPoint:[self getCoordinatePointForAnimationWithRadius:radius - 5 withIndex:i]],
[NSValue valueWithCGPoint:[self getCoordinatePointForAnimationWithRadius:radius withIndex:i]], nil]];
[moveAnimation setKeyTimes:[NSArray arrayWithObjects:
[NSNumber numberWithFloat:0],
[NSNumber numberWithFloat:0.5],
[NSNumber numberWithFloat:0.75],
[NSNumber numberWithFloat:1.0], nil]];
[moveAnimation setTimingFunctions:[NSArray arrayWithObjects:
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut], nil]];
moveAnimation.beginTime = CACurrentMediaTime() + 1 + (0.1 * i);
[layer addAnimation:opacityAnimation forKey:@"opacityAnimationUp"];
[layer addAnimation:moveAnimation forKey:@"moveAnimationUp"];
// That's not working correctly because of the delay
[layer setOpacity:1.0];
[layer setPosition:[self getCoordinatePointForAnimationWithRadius:radius withIndex:i]];
Thanks!
Best regards from Germany, Chris
It looks like the only thing missing is a backwards fill mode. That will cause the animation to display the first value as soon as it's added, even if the actual animation is delayed:
moveAnimation.fillMode = kCAFillModeBackwards;