问题描述
我的应用程序由约25帧的动画。该动画是由一个按钮触发,所有的工作。然而,在第一次调用动画,有几秒钟的延迟。
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.
我知道,这是因为图像需要在动画中的第一次运行缓存,我也〜2MB被缓存。
我希望苹果公司将实施[动画的prepareToPlay]为此方法。
I wish Apple would implement an [animation prepareToPlay] method for this reason.
在此期间,我跑在viewDidLoad中的动画。这个启动画面中缓存图像,但随后会显示动画。
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.
这首先是启动画面时强行缓存在初始化的图像,无动画播放在加载视图。 (阅读:自定义的UIImageView prepareToPlay方法)。 - 此解决方案将是理想
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.
第二个选择是保持我目前的code,在启动时运行的动画当视图已经被加载,但直到这第一个动画完成禁用调用按钮。由于的UIImageView没有它自己的完成通知,将最好的解决办法是建立等于动画持续时间的定时器,并启用按钮并表示定时器的结束?
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 ---如何强行缓存动画图像在初始化
推荐答案
我也面临问题,因为你的。我创造了我自己的问题在这里,我得到了很好的答案。看看这里:结果?
祝你好运!
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!
这篇关于加快第一的UIImageView动画(强制缓存图像)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!