我是核心动画的新手。每当我调用动画时,我的图像从其位置移动到屏幕的左上角,移动,然后返回到原始位置。如何使图像向左移动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"];
}
答案 0 :(得分:1)
对于您的情况,您可以跳过重型CA机器并使用块动画
// Your image is at starting position
[UIView animateWithDuration:1.5 animations:^{
CGRect newFrame = CGRectOffset(imView.frame, 50, 0);
imView.frame = newFrame;
}];
但是,如果您想知道如何正确处理此“快照”,请检查this url。