Speed up first UIImageView animation (force cache

2019-09-13 18:53发布

My app consists of an animation of about 25 frames. The animations is triggered by a button, and all is working. However, upon first invoking the animation, there is a few second delay.

I am aware that this is because the images need to be cached upon their first run in an animation, and I have ~2mb to be cached.

I wish Apple would implement an [animation prepareToPlay] method for this reason.

In the meantime, I'm running the animation within viewDidLoad. This caches the images during the splash screen, but then displays the animation.

There are two alternatives that I would like to consider.

This first is to forcibly cache the images upon initialization during the splash screen, without the animation playing upon loading the view. (read: custom UIImageView prepareToPlay method) --- This solution would be ideal.

The second alternative would be to keep my current code, running the animation at start-up once the view has been loaded, but disabling the invoking button until this first animation completes. Since UIImageView doesn't have it's own completion notification, would the best solution be to set up a timer equal to the animation duration and enable the button and the end of said timer?

Thanks in advance, Greg

TL;DR --- How to forcibly cache animation images upon initialization.

1条回答
做个烂人
2楼-- · 2019-09-13 19:42

I also faced problem as yours. I had created my own question here, and I got good answers. Check it out here: Does UIImageView cache images?
Good luck!

查看更多
登录 后发表回答