CATransform Layer's final position after rotation
I have done research and saw many questions regarding my issue. My issue is that, I have a CATransformLayer where I am drawing a 3D cube. Now to rotate the cube, I am using the CABasicAnimation and the code for that is as follows:
/* Code to add cube to the view */
transformLayer = [CATransformLayer layer];
transformLayer.anchorPoint = P(.5,.5);
transformLayer.bounds=CGRectMake(0,0,480,300 );
transformLayer.frame=CGRectMake(0,300, 480, 300);
transformLayer.position=P(240,150);
[transformLayer addSublayer:sideOne];
[transformLayer addSublayer:sideTwo];
[transformLayer addSublayer:sideThree];
[transformLayer addSublayer:sideFour];
[transformLayer addSublayer:sideFive];
[transformLayer addSublayer:sideSix];
transformLayer.anchorPointZ = Layer_Size/-2;
/* code to tilt the cube so that it looks 3D */
float degreesVariance = 130;
float radiansToRotate = DegreesToRadians( degreesVariance );
transformLayer.transform=CATransform3DMakeRotation(radiansToRotate, 1, 1, 0.0);
[rootLayer addSublayer:transformLayer];
The code for animation is as follows:
/* code to rotate the cube */
CABasicAnimation *spinningAnimationX;
spinningAnimationX = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];
spinningAnimationX.fromValue=0;
spinningAnimationX.toValue = [NSNumber numberWithFloat: DegreesToRadians(270) * 1* 1 /*rotations*/ * 2 ];
spinningAnimationX.duration = 2;
spinningAnimationX.repeatCount = 1.0;
[spinningAnimationX setRemovedOnCompletion:NO];
spinningAnimationX.fillMode = kCAFillModeForwards;
/* code to add to the layer */
CAAnimationGroup *group = [CAAnimationGroup animation];
[group setDuration:2];
[group setRemovedOnCompletion:NO];
[group setAnimations:[NSArray arrayWithObjects: spinningAnimationX, nil]];
[transformLayer addAnimation:group forKey:nil];
Despite setting the removeOnCompletion to NO and setFillMode, the CATransformLayer that I am trying to rotate doesn't end up in the angle after animation. It snaps back to the previous original position only.
Please help me out and let me know if I am overlooking anything.
链接地址: http://www.djcxy.com/p/74250.html上一篇: 如何旋转CAShapeLayer的中心点
下一篇: CAT转换图层在旋转后的最终位置