Speed up first UIImageView animation (force cache the images)

蹲街弑〆低调 提交于 2020-01-07 02:50:47

问题


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:


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!



来源:https://stackoverflow.com/questions/6893931/speed-up-first-uiimageview-animation-force-cache-the-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!