I am using this code to remove animate my UIView to the delete button on delete button press. Here's the code :
UIBezierPath *movePath = [UIBezierPath bezierPath];
[movePath moveToPoint:icon.center];
[movePath addQuadCurveToPoint:senderView.center
controlPoint:CGPointMake(senderView.center.x, icon.center.y)];
CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
moveAnim.path = movePath.CGPath;
moveAnim.removedOnCompletion = YES;
CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)];
scaleAnim.removedOnCompletion = YES;
CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];
opacityAnim.fromValue = [NSNumber numberWithFloat:1.0];
opacityAnim.toValue = [NSNumber numberWithFloat:0.1];
opacityAnim.removedOnCompletion = YES;
CAAnimationGroup *animGroup = [CAAnimationGroup animation];
animGroup.animations = [NSArray arrayWithObjects:moveAnim, scaleAnim, opacityAnim, nil];
animGroup.duration = 2.0;
[icon.layer addAnimation:animGroup forKey:nil];
And this actually animating the UIView to the delete button but after it's showing up in the same place again.
Animations apply to the presentation layer, not the model layer. You need to apply your changes to both. That's a fancy way of saying that when you do animate something, you also need to set it directly.
(Note that you may want to animate the view's
center
here rather than the layer'sposition
.)Chapter 7 of iOS 5 Programming Pushing the Limits has pages and pages on this if you want all the gory details. Here's the section on
removedOnCompletion
:Try changing the opacity animation to:
CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];
and then set the animation group's
removeOnCompletion
toNO
and itsfillMode
tokCAFillModeForwards
like Noah Witherspoon suggested.Set each animation’s
removedOnCompletion
toNO
and itsfillMode
tokCAFillModeForwards
.