Ios UI对象和Calayer的CABASICanization实践是否不同?

Ios UI对象和Calayer的CABASICanization实践是否不同?,ios,core-animation,calayer,cabasicanimation,Ios,Core Animation,Calayer,Cabasicanimation,我只是想知道这是否是用卡巴斯克动画制作炉匠动画的正确方法 在堆栈溢出中,我学习了如何通过在运行CABasicAnimation之前设置新位置来设置UI对象的动画: 为UI对象示例制作动画 gameTypeControl.center = CGPointMake(gameTypeControl.center.x, -slidingUpValue/2); CABasicAnimation *removeGameTypeControl = [CABasicAnimation animationWith

我只是想知道这是否是用卡巴斯克动画制作炉匠动画的正确方法

在堆栈溢出中,我学习了如何通过在运行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"];
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"];
现在,我已经在CALayer上尝试过这种方法,但似乎效果不同。让我得到同样的结果。我将ToValue设置为新的y位置,而不是像我在UI对象动画中那样使用值0

制作CALayer示例的动画

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"];
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
不是视图的直接底层,则设置其
位置,就像您在第二个示例的第一行中所做的那样,会启动不同的动画(隐式动画)。防止这种情况的方法是关闭隐式动画。因此,这个例子:

CompassLayer*c=(CompassLayer*)self.compass.layer;

[CATTransaction setDisableActions:是];//
serveBlock2
是一个CALayer<代码>[gameTypeControl layer]
是一个CALayer。示例是相同的。您好,您能否详细说明如何从上面的示例中的表示层和模型层自动了解新旧值?如果我理解正确:通过使用
setDisableAction:YES
我们可以防止
c
被隐式设置动画,这样在调用
cabasicanition
之前转换不会发生,对吗?谢谢。动画将在当前CATTransaction结束后很久才开始。@Unheilig转换(或任何其他更改)现在开始。但是用户看不到它,因为演示层在动画开始之前(稍后)不会开始移动。请参见动画何时运行以及如何工作。