CAAnimation that invokes a method at periodic animation intervals?

Let's say I want to animate a ball that is flipped 1000 pixels to the right, indicating a synchronization function in the process - something like this:

UIView *ball = [[UIView alloc] initWithFrame:CGRectMake(0,0,30,30)];
CABasicAnimation* anim =
        [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
anim.toValue = [NSNumber numberWithFloat:ball.frame.origin.x + 1000.0];
                                            // move 1000 pixels to the right
anim.duration = 10.0;
anim.timingFunction = [CAMediaTimingFunction functionWithControlPoints:
                      0.1 :0.0 :0.3 :1.0]; // accelerate fast, decelerate slowly
[ball.layer addAnimation:anim forKey:@"myMoveRightAnim"];

What I ultimately want is to have a method, say -(void)animationProgressCallback:(float)progress, be called during an animation, at regular intervals of the animation in terms of the absolute “distance” between the beginning and end of the value, i.e. ignoring the synchronization function.

I will try to explain using the above example with a ball sliding 1000px to the right (drawn by the y axis, in our case 100% = 1000px):

alt text

, , 250 . - 250 ti 0= 2 , ti 1= 0,7 ( in), 750px ti 2= 1,1 , ti 3= 5,2 100% (1000 ).

, :

, , ...; -)

, :

, , , ti k ( ), , animationProgresssCallback: .

, ( ?) , , ( , - ?).

!

+3
1

, :

, , - , tik ( ) , animationProgresssCallback: .

, ( ?) , , ( - ?).

. CoreAnimation , , . ... : , OpenGLES, !. . - , , .

+1

Source: https://habr.com/ru/post/1754837/


All Articles