soleil
soleil

Reputation: 13115

CAAnimationGroup with CAKeyframeAnimation and CABasicAnimation

I'm trying to animate a view along a curved path and scale it down at the same time:

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    pathAnimation.calculationMode = kCAAnimationPaced;
    pathAnimation.fillMode = kCAFillModeForwards;
    pathAnimation.removedOnCompletion = NO;
    //Setting Endpoint of the animation
    CGPoint endPoint = endCenter;
    CGMutablePathRef curvedPath = CGPathCreateMutable();
    CGPathMoveToPoint(curvedPath, NULL, viewOrigin.x, viewOrigin.y);
    CGPathAddCurveToPoint(curvedPath, NULL, viewOrigin.x+200, viewOrigin.y-150, endPoint.x+100, endPoint.y+10, endPoint.x, endPoint.y);
    pathAnimation.path = curvedPath;
    CGPathRelease(curvedPath);

    // Set up scaling
    CABasicAnimation *resizeAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    resizeAnimation.toValue = [NSNumber numberWithDouble:0.4];
    resizeAnimation.fillMode = kCAFillModeForwards;
    resizeAnimation.removedOnCompletion = NO;

    CAAnimationGroup *group = [CAAnimationGroup animation];
    group.fillMode = kCAFillModeForwards;
    group.removedOnCompletion = YES;
[group setAnimations:[NSArray arrayWithObjects: pathAnimation, resizeAnimation, nil]];
    group.duration = 3.7f;
    group.delegate = self;
    [group setValue:self.myView forKey:@"imageViewBeingAnimated"];

self.myView.center = endCenter;
self.myView.transform = self.myViewTransform;
[self.myView.layer addAnimation:group forKey:@"savingAnimation"];

The problem is that instead of the view scaling down gradually as it moves, it gets immediately scaled down, then moves along the path. I need to to scale down as it moves obviously.

Upvotes: 2

Views: 1731

Answers (1)

soleil
soleil

Reputation: 13115

Solved by doing this:

resizeAnimation.fromValue = [NSNumber numberWithDouble:1.0];

I don't understand why I have to do this. Seems like it should start from the default fromValue of the current transform.

Upvotes: 1

Related Questions