I would like to scale and translate the layer transform at the same time, but only the translation animation is performed. Here is the wrong code ...
Here I am creating a scale animation using the key path for scale.y:
self.mainImage.layer.anchorPoint = CGPointMake(0.5, 1);
CAKeyframeAnimation *mainAnimationScale = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale.y"];
mainAnimationScale.duration = 0.75;
mainAnimationScale.repeatCount = 0;
mainAnimationScale.removedOnCompletion = YES;
mainAnimationScale.autoreverses = NO;
mainAnimationScale.fillMode = kCAFillModeForwards;
mainAnimationScale.values = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:1.0],
[NSNumber numberWithFloat:1.0],
[NSNumber numberWithFloat:0.7],
[NSNumber numberWithFloat:1.0],
[NSNumber numberWithFloat:0.85],
[NSNumber numberWithFloat:1.0],
nil];
mainAnimationScale.keyTimes = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0],
[NSNumber numberWithFloat:0.65],
[NSNumber numberWithFloat:0.72],
[NSNumber numberWithFloat:0.84],
[NSNumber numberWithFloat:0.91],
[NSNumber numberWithFloat:1],
nil];
Here I am creating a translation animation with the key for translating .y:
CAKeyframeAnimation *mainAnimationTrans = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.y"];
mainAnimationTrans.duration = 0.75;
mainAnimationTrans.repeatCount = 0;
mainAnimationTrans.removedOnCompletion = YES;
mainAnimationTrans.autoreverses = NO;
mainAnimationTrans.fillMode = kCAFillModeForwards;
mainAnimationTrans.values = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:-250.0],
[NSNumber numberWithFloat:-250.0],
[NSNumber numberWithFloat:0],
nil];
mainAnimationTrans.keyTimes = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0],
[NSNumber numberWithFloat:0.65],
[NSNumber numberWithFloat:1],
nil];
Here I group them and apply them to the UIView layer:
CAAnimationGroup *theGroup = [CAAnimationGroup animation];
theGroup.duration = 0.75;
theGroup.repeatCount = 0;
theGroup.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
theGroup.animations = [NSArray arrayWithObjects:mainAnimationTrans, mainAnimationScale, nil];
[self.mainImage.layer addAnimation:theGroup forKey:@"layerAnimation"];
At first I tried to add the animation directly to this layer, but that didn't work either:
[self.mainImage.layer addAnimation:mainAnimationTrans forKey:@"transform.scale.y"];
[self.mainImage.layer addAnimation:mainAnimationTrans forKey:@"transform.translation.y"];
I tried every line that I can think of for keyPath values, and I assume this has something to do with the fact that I am animating two aspects of the conversion, but I thought that using the group would fix that. Alas...