CAT转换图层在旋转后的最终位置
我已经完成了研究并看到了许多关于我的问题的问题。 我的问题是,我有一个CATransformLayer,我正在绘制3D立方体。 现在旋转立方体,我使用的是CABasicAnimation,代码如下:
/* 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];
动画代码如下:
/* 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];
尽管将removeOnCompletion设置为NO和setFillMode,但我试图旋转的CATransformLayer不会以动画后的角度结束。 它只会回到之前的原始位置。
请帮助我,让我知道,如果我俯视任何东西。
链接地址: http://www.djcxy.com/p/74249.html