0

UIImageView transform.translation.x 动画在完成 toValue Process.for 后如何继续。例如:当按下按钮#1:从 1 到 55,按下按钮#2 从 55 到 110 ....如果它在按钮#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 回答