Reputation: 13441
Below is the code I use. The animation works. However, it jumped back to the original status after it. Is there anything wrong with my code. Thanks.
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
CABasicAnimation *expand=[CABasicAnimation animationWithKeyPath:@"transform"];
expand.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)];
expand.autoreverses=NO;
expand.removedOnCompletion=YES;
CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
opacityAnimation.toValue = [NSNumber numberWithFloat:0.0f];
opacityAnimation.autoreverses=NO;
opacityAnimation.removedOnCompletion=YES;
CAAnimationGroup *group=[CAAnimationGroup animation];
group.animations=[[NSArray alloc] initWithObjects:expand,opacityAnimation, nil];
group.duration=1.0;
group.fillMode=kCAFillModeForwards;
group.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[view1.layer addAnimation:group forKey:@"expand"];
}
Upvotes: 1
Views: 939
Reputation: 3012
CAAnimationGroup *group=[CAAnimationGroup animation];
group.animations=[[NSArray alloc] initWithObjects:expand,opacityAnimation, nil];
group.duration=1.0;
group.removedOnCompletion=NO;
group.fillMode=kCAFillModeForwards;
group.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[view1.layer addAnimation:group forKey:@"expand"];
Please try with removedOnCompletion as NO in group animation it may work for you.
Upvotes: 0
Reputation: 7346
An easy way to get rid of the jump-back is to explicitly update the model layer with the values that you are animating to by using CATransaction
without actions enabled:
[CATransaction begin];
[CATransaction setDisableActions:YES];
//this will update the model layer
view1.layer.transform = CATransform3DMakeScale(1.2, 1.2, 1.0);
view1.layer.opacity = 0.f;
//your basic animations will animate the presentation layer
/* your CABasicAnimations here */
[CATransaction commit];
Do not set removedOnCompletion
to NO
to keep the view in place, as this will make the animation go on for forever and the model layer will never get updated with the position that the presentation layer is displaying. You may also incur a performance penalty by never removing the animation since the GPU is animating a view that isn't really moving.
Upvotes: 0
Reputation: 5157
You are setting removedOnCompletion
to YES
which specifies that after completion the animation is to be removed. Try NO
instead.
Upvotes: 1