iOS CAKeyFrameAnimation 旋转
我编写了这个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的动画
keyPath
是错误的,它应该只是transform
而不是transform.rotation.x
。此外,由于您使用的是整数除法,因此您最终会在
tTrans.m34
中得到0
。它可能应该是-1.0/900
。Your animation
keyPath
is wrong, it should be justtransform
and nottransform.rotation.x
.Also, you'll end up with
0
intTrans.m34
because you're using integer division. It should probably be-1.0/900
.