3

我有 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;

}

4

0 回答 0