我只是想知道這是否是用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