2012-01-13 38 views
0

我有這段代碼來移動視圖。CAAnimation:動畫後不要重置

CABasicAnimation *theAnimation; 
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"]; 
theAnimation.duration=1; 
theAnimation.repeatCount=1; 
theAnimation.autoreverses=NO; 
theAnimation.fromValue=[NSNumber numberWithFloat:0]; 
theAnimation.toValue=[NSNumber numberWithFloat:-60]; 
[view.layer addAnimation:theAnimation forKey:@"animateLayer"]; 

問題是:動畫完成後,視圖的實際座標被複位。在動畫完成後,視圖是否可能保留在新的座標上?

謝謝。

回答

0

除了附加動畫動畫屬性的動畫之外,您還必須將屬性實際設置爲其最終值。瘋了,不是嗎?嘗試在添加動畫之前執行此操作:

[view.layer setValue:[NSNumber numberWithFloat:-60] forKey:@"transform.translation.x"]; 

我強烈建議您觀看WWDC 2011視頻「Core Animation Essentials」。它解釋了這一點,併爲使用Core Animation的任何人提供了許多有用的信息。你可以在這裏找到它:https://developer.apple.com/videos/wwdc/2011/

+0

謝謝。我發現了另一個答案: [theAnimation setFillMode:kCAFillModeForwards]; 然後它工作正常。感謝您的鏈接。 – user688262 2012-01-13 20:35:27