CAAnimationGroup Running Too Fast

164 views Asked by At

My CAAnimationGroup is running too fast. I want it to take a total of 50 seconds to do something, and it is doing it in about 3...it breezes through the first animation, and does the other one slow.

hover = [CABasicAnimation animationWithKeyPath:@"position"];
        hover.fillMode = kCAFillModeForwards;
        hover.removedOnCompletion = NO;
        hover.additive = YES; // fromValue and toValue will be relative instead of absolute values
        hover.fromValue = [NSValue valueWithCGPoint:CGPointZero];
        hover.toValue = [NSValue valueWithCGPoint:CGPointMake(26*22, 26*-10.0)]; // y increases downwards on iOS
        hover.autoreverses = FALSE; // Animate back to normal afterwards

        hover.repeatCount = 0; // The number of times the animation should repeat

       CABasicAnimation *fall = [CABasicAnimation animationWithKeyPath:@"position"];
        fall.fillMode = kCAFillModeForwards;
        fall.removedOnCompletion = NO;
        fall.additive = YES; // fromValue and toValue will be relative instead of absolute values
        fall.fromValue = [NSValue valueWithCGPoint:CGPointMake(26*22, 26*-10.0)];
        fall.toValue = [NSValue valueWithCGPoint:CGPointMake(26*22, guess1*700.0)]; // y increases downwards on iOS
        fall.autoreverses = FALSE; // Animate back to normal afterwards

        fall.repeatCount = 0; // The number of times the animation should repeat

        CAAnimationGroup*   group = [CAAnimationGroup new];
        group.beginTime = 0.;
        [group setDuration:50.0];
        group.animations = @[ hover, fall ];

        [theDude.layer addAnimation:group forKey:@"myHoverAnimation"];
1

There are 1 answers

1
Muhammad Abdul Subhan On

Judging by your implementation, I'm assuming you want a sequence of animations on an object theDude on it's position property.

You can achieve the animation by using CATransaction using it's completion blocks. More can be read here.