2011-08-26 85 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

很酷。讓我改變看到... –