1
我需要在時間T計算CABasicAnimation的進度以更新進度視圖。CABasicAnimation以可變速度進展
當進度是線性時,我只需計算每次經過的時間(感謝https://stackoverflow.com/a/20993376/2268168)。
事情是,動畫不是線性的,速度是可變的。
加快
mylayer.timeOffset = [mylayer convertTime:CACurrentMediaTime() fromLayer:nil];
mylayer.beginTime = CACurrentMediaTime();
mylayer.speed=2;
speed = 2;
放慢
mylayer.timeOffset = [mylayer convertTime:CACurrentMediaTime() fromLayer:nil];
mylayer.beginTime = CACurrentMediaTime();
mylayer.speed=0.5;
speed = 0.5;
如何計算動畫考慮變速的進展如何?
我試過了,但它似乎只在速度增加一次時才起作用。
CFTimeInterval elapsedTime = (CACurrentMediaTime() - animation.beginTime);
CFTimeInterval remainingTime = (totalDuration - elapsedTime)/speed;
speed = 1;
totalDuration = remainingTime+elapsedTime;
float progress = (totalDuration-remainingTime)/totalDuration;
我做錯了什麼?
感謝您的幫助!
你看過這個答案建議的技術:http://stackoverflow.com/a/19024971/294949。聰明的想法是添加一個圖層來爲一個矩形設置動畫,並使用該矩形的大小作爲進度的度量。 – danh