iOS CAKeyFrameAnimation旋转

时间:2011-08-26 12:27:50

标签: objective-c ios core-animation calayer 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"];

感谢任何帮助。感谢...

1 个答案:

答案 0 :(得分:1)

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

此外,您最终会在0中使用tTrans.m34因为您正在使用整数除法。应该是-1.0/900