Restoring animation where it left off when app resumes from background

后端 未结 10 1307
广开言路
广开言路 2020-11-28 18:57

I have an endlessly looping CABasicAnimation of a repeating image tile in my view:

a = [CABasicAnimation animationWithKeyPath:@\"position\"];
a         


        
10条回答
  •  攒了一身酷
    2020-11-28 19:17

    It's surprising to see that this isn't more straightforward. I created a category, based on cclogg's approach, that should make this a one-liner.

    CALayer+MBAnimationPersistence

    Simply invoke MB_setCurrentAnimationsPersistent on your layer after setting up the desired animations.

    [movingView.layer MB_setCurrentAnimationsPersistent];
    

    Or specify the animations that should be persisted explicitly.

    movingView.layer.MB_persistentAnimationKeys = @[@"position"];
    

提交回复
热议问题