iPhone Best practices for large number of animations using UIImageView

自作多情 提交于 2019-12-09 03:56:39

问题


Just requesting a little advice animating images on the iphone. I'm building an app that consists of a character with 5 animations.

Each animation consists of roughly 50 images with an average duration of 3 seconds.

I was going to create an array of images for each animation, have these as the source for an UIImageView and switch these as needed. But as you can guess this approach kills my iphone's memory and thus the app. (250 images @ 130K each!)

So this got me wondering how other people get around this? Maybe change the animations to movies?

Thanks for any advice.


回答1:


I'd recommend the movie route, if you can get away with it. It'll be cleaner and likely much more performant.

However, if you're stuck with images for some reason, here's performance from loading 5000 full-frame images in succession:

[UIImage imageWithData:...] // 44.8 seconds

[UIImage imageWithContentsOfFile:...] // 52.3 seconds

[[UIImage alloc] initWithContentsOfFile:…] // 351.8 seconds

[UIImage imageNamed:...] // hung due to caching



回答2:


Have you tried setting the animationImages property on a UIImageView with an array of UIImages representing your frames. I have done that in the past and it worked pretty well, but I didn't have as many images as you in my animation.

If there is too much data in your images, you may have to do something more complex, like a sprite atlas. That method combines a bunch of your frames as one image and then animates the frames by changing the viewable portion of the big image. That way the whole thing loads at once and the animation just changes the part of the image that the user sees. Cocos2D has a bunch of functionality around sprite animation. If the animationImages thing doesn't work, you might want to try that.

--Mike



来源:https://stackoverflow.com/questions/4496224/iphone-best-practices-for-large-number-of-animations-using-uiimageview

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