0

任何人都知道为什么我不能让这个简单的动画工作?它只是不玩。

self.scene = [SCNScene scene];

SCNNode *sun = [SCNNode nodeWithGeometry:[SCNSphere sphereWithRadius:5.0]];
SCNNode *moon = [SCNNode nodeWithGeometry:[SCNSphere sphereWithRadius:2.0]];

moon.position = SCNVector3Make(7.0, 7.0, 7.0);
moon.pivot = CATransform3DMakeTranslation(-7.0, -7.0, -7.0);

CABasicAnimation *startAnim = [CABasicAnimation animationWithKeyPath:@"rotation"];
startAnim.duration = 5;
startAnim.repeatCount = MAXFLOAT;
startAnim.toValue =[NSValue valueWithSCNVector4:SCNVector4Make(0.0, 0.0, 0.0,1.0)];
startAnim.timingFunction =[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

[moon addAnimation:startAnim forKey:@"rotate"];
[sun addChildNode:moon];
[[self.scene rootNode] addChildNode:sun];

我认为问题是...

 startAnim.toValue =[NSValue valueWithSCNVector4:SCNVector4Make(0.0, 0.0, 0.0,1.0)];

干杯

4

2 回答 2

3

事实上 SCNVector4Make(0.0, 0.0, 0.0,1.0) 不是有效的旋转。“旋转”是由 4 个浮点 {xyzw} 组成的轴角。3个第一个浮点数xyz代表轴,w是以弧度为单位的旋转。所以 (0.0, 0.0, 0.0) 不是一个有效的轴(或者在最好的情况下它代表一个空旋转)

于 2012-08-18T20:08:52.110 回答
0

我也无法让您的示例使用“旋转”键路径,但我可以使用“转换”。例如:

CABasicAnimation *startAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
startAnim.duration = 5;
startAnim.repeatCount = MAXFLOAT;
startAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(3.14, 0.0, 1.0, 0.0)];
startAnim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[moon addAnimation:startAnim forKey:@"transform"];
于 2013-01-22T04:50:27.960 回答