iOS CAKeyFrameAnimation 旋转

发布于 2024-12-01 16:58:15 字数 2340 浏览 4 评论 0原文

我编写了这个 CAKEyFrameAnimaton 来在 X 轴上旋转 CALayer。但它不旋转。我在这里做错了什么?

CAKeyframeAnimation *topFoldAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.x"];
topFoldAnimation.duration             = 15;
topFoldAnimation.repeatCount          = 1;
topFoldAnimation.removedOnCompletion  = NO;
topFoldAnimation.autoreverses         = NO;
topFoldAnimation.fillMode             = kCAFillModeForwards;

CATransform3D tTrans                  = CATransform3DIdentity;
tTrans.m34                            = -1/900;

topFoldAnimation.values               = [NSArray arrayWithObjects:
                                        [NSValue valueWithCATransform3D:CATransform3DRotate(tTrans,DEGREES_TO_RADIANS(0),1,0,0)],
                                        [NSValue valueWithCATransform3D:CATransform3DRotate(tTrans,DEGREES_TO_RADIANS(-30),1,0,0)],
                                        [NSValue valueWithCATransform3D:CATransform3DRotate(tTrans,DEGREES_TO_RADIANS(-60),1,0,0)],
                                        [NSValue valueWithCATransform3D:CATransform3DRotate(tTrans,DEGREES_TO_RADIANS(-90),1,0,0)],
                                           nil];
topFoldAnimation.keyTimes             = [NSArray arrayWithObjects:
                                          [NSNumber numberWithFloat:0.00], 
                                          [NSNumber numberWithFloat:0.25],
                                          [NSNumber numberWithFloat:0.50],
                                          [NSNumber numberWithFloat:1.00],
                                           nil];
topFoldAnimation.timingFunctions      = [NSArray arrayWithObjects:
                                         [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear], 
                                         [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear],
                                         [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear],
                                         [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear],
                                           nil];
[[backgroundAnimationLayer.sublayers objectAtIndex:1] addAnimation:topFoldAnimation forKey:@"transform.rotation.x"];

任何帮助表示赞赏。谢谢...

I have written this CAKEyFrameAnimaton to rotate a CALayer on it's X-axis. But it is not rotating. What am I doing wrong here?

CAKeyframeAnimation *topFoldAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.x"];
topFoldAnimation.duration             = 15;
topFoldAnimation.repeatCount          = 1;
topFoldAnimation.removedOnCompletion  = NO;
topFoldAnimation.autoreverses         = NO;
topFoldAnimation.fillMode             = kCAFillModeForwards;

CATransform3D tTrans                  = CATransform3DIdentity;
tTrans.m34                            = -1/900;

topFoldAnimation.values               = [NSArray arrayWithObjects:
                                        [NSValue valueWithCATransform3D:CATransform3DRotate(tTrans,DEGREES_TO_RADIANS(0),1,0,0)],
                                        [NSValue valueWithCATransform3D:CATransform3DRotate(tTrans,DEGREES_TO_RADIANS(-30),1,0,0)],
                                        [NSValue valueWithCATransform3D:CATransform3DRotate(tTrans,DEGREES_TO_RADIANS(-60),1,0,0)],
                                        [NSValue valueWithCATransform3D:CATransform3DRotate(tTrans,DEGREES_TO_RADIANS(-90),1,0,0)],
                                           nil];
topFoldAnimation.keyTimes             = [NSArray arrayWithObjects:
                                          [NSNumber numberWithFloat:0.00], 
                                          [NSNumber numberWithFloat:0.25],
                                          [NSNumber numberWithFloat:0.50],
                                          [NSNumber numberWithFloat:1.00],
                                           nil];
topFoldAnimation.timingFunctions      = [NSArray arrayWithObjects:
                                         [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear], 
                                         [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear],
                                         [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear],
                                         [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear],
                                           nil];
[[backgroundAnimationLayer.sublayers objectAtIndex:1] addAnimation:topFoldAnimation forKey:@"transform.rotation.x"];

Any help is appreciated. Thanks...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

離殇 2024-12-08 16:58:15

你的动画keyPath是错误的,它应该只是transform而不是transform.rotation.x

此外,由于您使用的是整数除法,因此您最终会在 tTrans.m34 中得到 0。它可能应该是-1.0/900

Your animation keyPath is wrong, it should be just transform and not transform.rotation.x.

Also, you'll end up with 0 in tTrans.m34 because you're using integer division. It should probably be -1.0/900.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文