I want the easing function to be equivalent to UIViewAnimationCurveEaseInOut, but I donβt see that Apple is revealing this as a function.
Apple provides a CAMediaTimingFunction
via [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut]
, which you can call getControlPointAtIndex:values:
to get breakpoints. You will find out that this is cubic bezier with control points (0, 0), (0.42, 0), (0.58, 1), (1, 1).
This gives you the Bezier function f(n)
, which displays as a 2d value
chart along y, versus time
, along x. Therefore, to get the correct value, just solve for n
where x = time
and read the value.
In particular, in this function:
fx(n) = (1-n)^3 * 0 + 3(1-n)^2 * n * 0.42 + 3(1-n) * n^2 * 0.58 + n^3 * 1 = 3(1-n)^2 * n * 0.42 + 3(1-n) * n^2 * 0.58 + n^3 = 1.26(1 - 2n + n^2) * n + 1.74 (1 - n) * n^2 + n^3 = 1.26n - 2.52n^2 + 1.26n^3 + 1.74n^2 - 1.74n^3 + n^3 = 1.26n - 0.78n^2 + 0.52n^3
(disclaimer: not issued immediately, please check)
To get the value at time 0.5, solve for n in:
0.5 = 1.26n - 0.78n^2 + 0.52n^3
Then connect it to the equivalent of fy(n)
. There is a formula for solving cubic , but getting into it is slightly related, therefore (i) read the Wikipedia article and use the formula; or (ii) write a numerical solver, for example. by binary search. This particular cube behaves very well, having only one solution at a time.