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 に答える