CABasicAnimation从fromValue继续

时间:2012-01-27 17:39:13

标签: objective-c xcode cabasicanimation

如何在完成toValue Process后继续UIImageView transform.translation.x动画。例如:按下按钮#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"];

}

1 个答案:

答案 0 :(得分: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;

希望这有效。

基本动画和关键帧动画之间的主要区别在于,关键帧允许您沿路径指定多个点。