I have a problem with CAAnimationGroup. I have a view called animeView and I want to apply a 3D rotation around Y axis and a scaling transform at the same time. The rotation and scaling animations work perfectly fine separately! But when I add them to a CAAnimationGroup Non of the animations occur!
What is the problem?
CAKeyframeAnimation *rotation = [CAKeyframeAnimation animation];
CATransform3D rotationTransform = CATransform3DMakeRotation(M_PI, 0.0f, 1.0f, 0.0f);
rotationTransform.m34 = 1.0 / -500;
rotation.values = [NSArray arrayWithObjects:
[NSValue valueWithCATransform3D:CATransform3DMakeRotation(0.0f, 0.0f, 1.0f, 0.0f)],
[NSValue valueWithCATransform3D:rotationTransform],
[NSValue valueWithCATransform3D:CATransform3DMakeRotation(2.0*M_PI, 0.0f, 1.0f, 0.0f)] ,nil];
CAKeyframeAnimation *trans = [CAKeyframeAnimation animation];
trans.values = [NSArray arrayWithObjects:[NSValue valueWithCATransform3D:CATransform3DIdentity],[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.5, 0.5, 0.5)],[NSValue valueWithCATransform3D:CATransform3DIdentity], nil];
CAAnimationGroup *group = [CAAnimationGroup animation];
group.delegate = self;
[group setAnimations: [NSArray arrayWithObjects:rotation, trans, nil]];
group.duration = 2;
group.repeatCount = 3;
[self.animView.layer addAnimation:group forKey:nil];
There are two things that is strange with the code you’ve provided.
The way I see it is that you have two transform key-frame animations with the same number of values (three). Therefore you should calculate the total transformation matrix (both scale and rotate in one matrix) and only add that animation to your view.
It would look something like this (I’ve added lots of comments to explain what sis happening):