延迟后CAKeyframeAnimation重复

时间:2012-06-26 16:29:14

标签: iphone objective-c xcode animation cakeyframeanimation

我有3个uiviews,它们添加了一个CAKeyframeAnimation图层来反弹。目前我在延迟后将这些添加到每个uiview并将它们设置为重复。

我需要他们做的是重复但是经过一段时间后。所以查看1个动画,但等到视图2和3之后再次开始动画之前。

我似乎无法在提及重复启动时间延迟重复CAKeyframeAnimation的文档中的任何地方阅读。

任何人都可以想到让观点之间出现延迟的想法吗?

由于

到目前为止

代码:

- (CAKeyframeAnimation *)jumpAnimation
 {
// these three values are subject to experimentation
CGFloat initialMomentum = 80.0f; // positive is upwards, per sec
CGFloat gravityConstant = 250.0f; // downwards pull per sec
CGFloat dampeningFactorPerBounce = 0.6;  // percent of rebound

// internal values for the calculation
CGFloat momentum = initialMomentum; // momentum starts with initial value
CGFloat positionOffset = 0; // we begin at the original position
CGFloat slicesPerSecond = 60.0f; // how many values per second to calculate
CGFloat lowerMomentumCutoff = 5.0f; // below this upward momentum animation ends

CGFloat duration = 0;
NSMutableArray *values = [NSMutableArray array];

do 
{
    duration += 1.0f/slicesPerSecond;
    positionOffset+=momentum/slicesPerSecond;

    if (positionOffset<0)
    {
        positionOffset=0;
        momentum=-momentum*dampeningFactorPerBounce;
    }

    // gravity pulls the momentum down
    momentum -= gravityConstant/slicesPerSecond;

    CATransform3D transform = CATransform3DMakeTranslation(0, -positionOffset, 0);
    [values addObject:[NSValue valueWithCATransform3D:transform]];
} while (!(positionOffset==0 && momentum < lowerMomentumCutoff));


CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
animation.duration = duration;
animation.fillMode = kCAFillModeForwards;
animation.values = values;
animation.repeatCount = HUGE_VAL;
animation.delegate =self;
animation.autoreverses = YES;

return animation;

}

0 个答案:

没有答案