0

toValue プロセスが完了した後、UIImageView transform.translation.x アニメーションを続行するにはどうすればよいですか。ボタン#2 の位置を変更し、ボタン#5 をクリックすると、55*2 から 55*5 になります。

- (void)animateArrow{
CABasicAnimation *theAnimation;


theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
theAnimation.duration=0.4;
theAnimation.repeatCount=1;
theAnimation.toValue=[NSNumber numberWithFloat:50];

[buttonArrow.layer setValue:theAnimation.toValue forKey:theAnimation.keyPath];
[buttonArrow.layer addAnimation:theAnimation forKey:@"transform.translation.x"];

}

4

1 に答える 1

1

次のような配列で、アニメーション パスに沿って複数のポイントを提供することを検討する必要があります。

CAKeyframeAnimation *downMoveAnimation;
downMoveAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.y"];
downMoveAnimation.duration = 12;
downMoveAnimation.repeatCount = 1;
downMoveAnimation.values = [NSArray arrayWithObjects:           
                             [NSNumber numberWithFloat:20], 
                             [NSNumber numberWithFloat:220], 
                             [NSNumber numberWithFloat:290], nil]; 
downMoveAnimation.keyTimes = [NSArray arrayWithObjects:     
                               [NSNumber numberWithFloat:0], 
                               [NSNumber numberWithFloat:0.5], 
                               [NSNumber numberWithFloat:1.0], nil]; 

downMoveAnimation.timingFunctions = [NSArray arrayWithObjects:
                                      [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn],        // from keyframe 1 to keyframe 2
                                      [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut], nil]; // from keyframe 2 to keyframe 3

downMoveAnimation.removedOnCompletion = NO;
downMoveAnimation.fillMode = kCAFillModeForwards;

これがうまくいくことを願っています。

基本的なアニメーションとキー フレーム アニメーションの主な違いは、キー フレームではパスに沿って複数のポイントを指定できることです。

于 2012-05-03T07:22:03.597 に答える