【问题标题】:CABasicAnimation Continue from fromValueCABasicAnimation 从 fromValue 继续
【发布时间】:2012-01-27 17:39:12
【问题描述】:

如何在 UIImageView transform.translation.x 动画完成 toValue Process.for 后继续它。例如:按下按钮#1 时:从 1 到 55,按下按钮#2 从 55 到 110....和如果它在button#2的位置,然后你点击button#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"];

}

【问题讨论】:

    标签: objective-c xcode cabasicanimation


    【解决方案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;
    

    希望这可行。

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

    【讨论】:

    • 谢谢伙计。像魅力一样工作..:)
    猜你喜欢
    • 1970-01-01
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多