Search code examples
iphoneobjective-ccocoa-touchcore-animation

Core Animation formula for movement


I have a formula for setting x and y of an object at every frame. In a classic for (i=0; i < x; i++) loop, I can bind it to the i value and calculate x and y values based on the current value of i that represents the passing of time.

I intended to use it with a NSTimer object and update the coordinate points at every tick, but I've seen that NSTimer is descouraged for animations.

Can I do the same with Core Animation? Instead of the standard "from here to there in given seconds", I would need a method to "update the position with this formula".


Solution

  • If you can model your function with a cubic Bézier curve, you can create a custom CAMediaTimingFunction instance and assign it to the animation's timingFunction property.

    If a Bézier curve does not work, a CAKeyframeAnimation might indeed work.