Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to animate CATransform3D with multiple transforms?

Basically, I'm rotating a layer about a point as :

CATransform3D transform = CATransform3DIdentity;
transform.m34 = 1.0 / -500;
transform = CATransform3DTranslate(transform, rotationPoint.x-center.x, rotationPoint.y-center.y, 0.0);
transform = CATransform3DRotate(transform, (rotationAngleFor) * M_PI / 180.0f, 0.0, 1.0, 0);
transform = CATransform3DTranslate(transform, center.x-rotationPoint.x, center.y-rotationPoint.y, 0.0);

I also create a layer, add it to a bigger layer and then apply the transform to it:

[self.layer addSublayer:myLayer];
myLayer.transform = transform;

How to animate this?

Note- Putting this in a UIView animation block doesn't work.

like image 972
tipycalFlow Avatar asked Jan 16 '23 14:01

tipycalFlow


1 Answers

Edit: As @DuncanC pointed out my description did not match the actual code.

You can use a CABasicAnimation that is added to the layer as follows.

CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath: @"transform"];

    <here goes your definition of transform>

transformAnimation.toValue = [NSValue valueWithCATransform3D:newTransform];
transformAnimation.duration = 10;
[self.layer addAnimation:transformAnimation forKey:@"transform"];

This animation performs a continuous change of the transform property of the layer from the original value of the transform property of the layer to the newTransform transformation. The change takes 10 seconds.

like image 115
Jan Christiansen Avatar answered Jan 31 '23 10:01

Jan Christiansen