iPhone 使用 UIImageView 处理大量动画的最佳实践 [英] iPhone Best practices for large number of animations using UIImageView

查看:16
本文介绍了iPhone 使用 UIImageView 处理大量动画的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是请求一些关于在 iphone 上动画图像的建议.我正在构建一个由具有 5 个动画的角色组成的应用程序.

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

每个动画由大约 50 张图像组成,平均持续时间为 3 秒.

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

我打算为每个动画创建一个图像数组,将它们作为 UIImageView 的源并根据需要切换它们.但正如你可以猜到的那样,这种方法会杀死我 iphone 的内存,从而杀死应用程序.(250 张图片,每张 130K!)

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?

感谢您的建议.

推荐答案

如果可以的话,我会推荐电影路线.它会更干净,并且可能会更高效.

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

但是,如果您因某种原因无法使用图像,以下是连续加载 5000 张全帧图像的性能:

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

这篇关于iPhone 使用 UIImageView 处理大量动画的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆