Iphone 如何使用Cabasicanization从一点移动到另一点?

Iphone 如何使用Cabasicanization从一点移动到另一点?,iphone,objective-c,ios,caanimation,Iphone,Objective C,Ios,Caanimation,我正在使用CABasicAnimation在我的应用程序中从一个点到另一个点执行动画移动对象,但在动画完成移动到目标点后,它始终显示在起点。如何防止动画完成后在开始点不显示 提前谢谢,试试这个 [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1.0]; CGRect frame=objectName.frame; frame.origin.x=frame.origin.x-20;//change the

我正在使用
CABasicAnimation
在我的应用程序中从一个点到另一个点执行动画移动对象,但在动画完成移动到目标点后,它始终显示在起点。如何防止动画完成后在开始点不显示

提前谢谢,

试试这个

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
CGRect frame=objectName.frame;
frame.origin.x=frame.origin.x-20;//change the point according to you
frame.origin.y=frame.origin.y-20;//change the point according to you
objectName.frame=frame;
[UIView commitAnimations];

看起来您忘记设置对象的实际终点值。使用
cabasicanitation
可以添加动画,并相应地设置属性。

此代码工作正常,但实际上我想使用核心动画来执行复杂的动画。例如,在用户定义的路径上移动对象。这样,在动画完成后,您必须更改对象的位置,以便每当动画完成时,对象都会保留到目标点此处我的代码:CABasicAnimation*translateAnim=[CABasicAnimation WithKeyPath:@“transform.translation.y”];translateAnim.duration=1.0;translateAnim.fromValue=[NSNumber numberWithFloat:0.0f];translateAnim.toValue=[NSNumber numberWithFloat:-100.f];[图层添加动画:translateAnim forKey:@“移动”];