我已經看了四周,但我一直未能找到這個簡單的問題的答案。有沒有辦法讓Swift CABasicAnimation動畫的效果永久化? (意思是當動畫結束後,視圖不會重置到它在動畫開始之前的狀態。)迅速使動畫效果永久
0
A
回答
1
有沒有一種方法,使雨燕CABasicAnimation動畫永久的效果
絕對如此。只需將您正在動畫的屬性設置爲動畫結束時的值即可。您可以在創建和添加動畫的同時執行此操作。 (您可能會想打開隱動畫關閉當你做到這一點,這樣你就不會動畫這個改變。)
例子從我自己的代碼(我動畫的transform
一個名爲arrow
使其旋轉層):
let startValue = arrow.transform
let endValue = CATransform3DRotate(
startValue, CGFloat(M_PI)/4.0, 0, 0, 1)
// change the layer, without implicit animation
// THIS IS WHAT YOU ARE ASKING ABOUT
CATransaction.setDisableActions(true)
arrow.transform = endValue
// construct the explicit animation
let anim = CABasicAnimation(keyPath:"transform")
anim.duration = 0.8
anim.fromValue = NSValue(CATransform3D:startValue)
anim.toValue = NSValue(CATransform3D:endValue)
// ask for the explicit animation
arrow.addAnimation(anim, forKey:nil)
+0
有關此代碼背後原理的完整討論,請參閱我的書:http://www.apeth.com/iOS書/ ch17.html#_using_a_cabasicanimation – matt
你應該fillModes https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CAMediaTiming_protocol/index.html#/看看/ apple_ref/doc/constant_group/Fill_Modes –