Search code examples
objective-ccore-animation

Core Animation - How to calculate duration so that two lines of different length are drawn at the same rate


I have two lines at different lengths

Line1 -----

Line2 -------------

How can I calculate the animation duration for each line so that they both are drawn at the same speed.

At the moment, I have a set value for duration

line1.duration = 1;

line2.duration = 1;

Because of the different lengths, line1's animation is slower than line2.

How can I calculate the animation duration with a fixed speed?

EDIT

Forgot to mention that line1 doesn't know line2's length as the lines are drawn in a loop. What i'm after is a constant velocity calculation / pixels per seconds


Solution

  • Try this:

    line2.duration = lengthOfLine2 / lengthOfLine1 * line1.duration;
    

    (substitute the appropriate values.)