0

我是核心动画的新手。每次我调用动画时,我的图像都会从它的位置移动到屏幕的左上角,移动,然后回到原来的位置。如何使图像向左移动 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"];

}
4

1 回答 1

1

对于您的情况,您可以跳过重型 CA 机器并使用块动画

// Your image is at starting position
[UIView animateWithDuration:1.5 animations:^{
        CGRect newFrame = CGRectOffset(imView.frame, 50, 0);
        imView.frame = newFrame;
    }];

但是,如果您想知道如何正确处理此“快速恢复”,请查看此 url

于 2013-02-11T06:04:40.723 回答