不要发布关于 UIView 动画的答案 我了解 UIView,我正在学习核心动画。我试图让图像向右移动 50 个单位,但我遇到了很多问题。首先,当动画被调用时,图像会跳到一个新的位置,运行,然后跳回原来的位置。我希望它简单地向右移动 50 个单位,停止,如果按下按钮,再次移动。我花了很多时间研究,我似乎无法找到问题所在。我的代码:
-(IBAction)preform:(id)sender{
CGPoint point = CGPointMake(imView.frame.origin.x, imView.frame.origin.y);
imView.layer.position = point;
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"position.x"];
anim.fromValue = [NSValue valueWithCGPoint:point];
anim.toValue = [NSValue valueWithCGPoint:CGPointMake(point.x + 50, point.y)];
anim.duration = 1.5f;
anim.repeatCount =1;
anim.removedOnCompletion = YES;
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[imView.layer addAnimation:anim forKey:@"position.x"];
imView.layer.position = point;
}