动画完成后,CABasicAnimation不会更改其位置属性 [英] CABasicAnimation not changing its position property after animation completes

查看:404
本文介绍了动画完成后,CABasicAnimation不会更改其位置属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将CABasicAnimation应用于动画效果良好的图层的位置属性,但是在动画完成后它会回到原始位置,如何避免这种情况并使图像仅保持在动画位置?

i am applying CABasicAnimation for position property of a layer it is animating well but after animation complete its coming back to original position how to avoid that and to make image to stay in animated position only?

推荐答案

有几种不同的方法可以解决这个问题。我最喜欢的是在动画结束时设置对象,并使用fromValue而不是toValue来创建动画。您还可以设置fromValue和toValue来创建此效果。 ie

There are a few different ways to solve this. My favorite is to set the object at the end of the animation, and use fromValue instead of toValue to create the animation. You can also set both fromValue and toValue to create this effect. ie

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
animation.duration = 1.0;
animation.fromValue = [NSValue valueWithCGPoint:startPoint];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

viewToAnimate.center = endPoint;
[viewToAnimate.layer addAnimation:animation forKey:@"slide"];

另一种方法是将自己设置为委托并实施:

The other way to do this is to set yourself as the delegate and implement:

-(void)animationDidStop:(id)sender finished:(BOOL)finished {
     viewToAnimate.center = endPoint;
}

这篇关于动画完成后,CABasicAnimation不会更改其位置属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆