我只是想知道这是否是用CABasicAnimation动画CALayer的正确方法。对于UI对象和CALayers,CABasicAnimation练习是否有所不同?
在堆栈溢出我已经学会了如何通过运行一个CABasicAnimation之前设置一个新的位置,以动画UI对象:
动画UI目标实例
gameTypeControl.center = CGPointMake(gameTypeControl.center.x, -slidingUpValue/2);
CABasicAnimation *removeGameTypeControl = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
[removeGameTypeControl setFromValue:[NSNumber numberWithFloat:slidingUpValue]];
[removeGameTypeControl setToValue:[NSNumber numberWithFloat:0]];
[removeGameTypeControl setDuration:1.0];
[removeGameTypeControl setTimingFunction:[CAMediaTimingFunction functionWithControlPoints:0.8 :-0.8 :1.0 :1.0]];
[[gameTypeControl layer] addAnimation:removeGameTypeControl forKey:@"removeGameTypeControl"];
现在我已经试过这个方法在CALayer上,但它似乎工作不同。对我来说,得到相同的结果。我已经将ToValue设置为新的y位置,而不是像使用UI对象动画一样使用值0。
动画一个CALayer的实例
serveBlock2.position = CGPointMake((screenBounds.size.height/4)*3, -screenBounds.size.width/2);
CABasicAnimation *updateCurrentServe2 = [CABasicAnimation animationWithKeyPath:@"position.y"];
updateCurrentServe2.fromValue = [NSNumber numberWithFloat:slidingUpValue/2];
[updateCurrentServe2 setToValue:[NSNumber numberWithFloat:-screenBounds.size.width/2]];
[updateCurrentServe2 setDuration:1.0];
[serveBlock2 addAnimation:updateCurrentServe2 forKey:@"serveBlock2 updateCurrentServe2"];
这是正确的吗?我做对了吗?
'serveBlock2'是一个CALayer。 '[gameTypeControl层]'是一个CALayer。这些例子是一样的。 – matt