我是核心动画的新手。每次我调用动画时,我的图像都会从它的位置移动到屏幕的左上角,移动,然后回到原来的位置。如何使图像向左移动 50 个单位,停止,然后在再次按下按钮时重复。代码:
-(IBAction)preform:(id)sender{
CGPoint point = CGPointMake(50, 50);
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"position"];
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"];
}