2011-08-26 54 views
2

我已经写了这个CAKEyFrameAnimaton在它的X轴上旋转一个CALayer。但它不旋转。我在这里做错了什么?iOS CAKeyFrameAnimation旋转

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

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

此外,由于您使用的是整数除法,因此您将以0结尾为tTrans.m34。它应该可能是-1.0/900

+0

是的,我正在分配m34来获得2.5D透视图。为什么subLayer?如果我将它应用到图层,所有子图层都应该进行转换,对吧? –

+0

对,我以某种方式假定'm34'只对'subLayerTransform'产生影响,因为我一直以这种方式使用它,但似乎并非如此。尽管如此,你在这里有效地分配0,这肯定不会产生预期的效果。 – omz

+0

很酷。让我改变看到... –