CAKeyframeAnimation with loop

I am trying to create a CAKeyframeAnimation with a slight twist. I want part of the keyframe animation to loop for a while before going straight to the end. For instance:

Intro: play keyframes 0 to 10
Loop:  play keyframes 11 to 15 (repeat for a while)
End:   play keyframes 16 to 20

CAKeyframeAnimation does not seem to provide enough flexibility, so the only way I can solve this is to create 3 different keyframe animations.

Is there a better solution out there?

+3
source share
1 answer

Since no one wanted to answer this and assumed that you hadn't solved it yet, I thought I'd give him bash.

First, I would create a property that stores the state of the animation. i.e

NSUIneteger animationState; 

:   0 = idleState;   1 = startState;   2 = loopedState;   3 = endState;

BOOL , ;

BOOL haltAnimation;

State 0. , CAAnimation , . haltAnimation false;

animationDidStart ( ) - :

-(void)animationDidStart {
    switch(animationState) {
        case 0:
            animationState = 1;
            break;
        case 1:
            animationState = 2;
            break;
        case 2:
            if(haltAnimation)
                animationState = 3;
    }
}

- :

-(void)animationDidFinish {
    swtich(animationState) {
        case 1:
            /*apply stage 2 animation and assign delegate to self*/
            break;
        case 2:
            if(!haltAnimation) {
                /*apply stage 2 animation and assign delegate to self*/
            } else {
                /*apply stage 3 animation and assign delegate to self*/
            }
            break;
        case 3:
            animationState = 0;
            break;
    }
}

, , 2 , haltAnimation true.

, . - .

+2

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


All Articles