我在视图控制器上有5个动画。这已经非常耗费内存,因为它们具有视网膜质量。
这是我的代码
//Panel 1 Animation
NSArray *panel1Frames = [NSArray array];
panel1Frames = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"origami_panel010001.png"],
[UIImage imageNamed:@"origami_panel010002.png"],
[UIImage imageNamed:@"origami_panel010004.png"],
[UIImage imageNamed:@"origami_panel010005.png"],
[UIImage imageNamed:@"origami_panel010006.png"],
[UIImage imageNamed:@"origami_panel010007.png"],
[UIImage imageNamed:@"origami_panel010008.png"],
[UIImage imageNamed:@"origami_panel010009.png"],
[UIImage imageNamed:@"origami_panel010010.png"],
[UIImage imageNamed:@"origami_panel010011.png"],
[UIImage imageNamed:@"origami_panel010012.png"],
[UIImage imageNamed:@"origami_panel010013.png"],
[UIImage imageNamed:@"origami_panel010014.png"],
[UIImage imageNamed:@"origami_panel010015.png"],
[UIImage imageNamed:@"origami_panel010016.png"],
[UIImage imageNamed:@"origami_panel010017.png"],
[UIImage imageNamed:@"origami_panel010018.png"],
[UIImage imageNamed:@"origami_panel010019.png"],
[UIImage imageNamed:@"origami_panel010020.png"],
[UIImage imageNamed:@"origami_panel010021.png"],
[UIImage imageNamed:@"origami_panel010022.png"],
[UIImage imageNamed:@"origami_panel010023.png"],
[UIImage imageNamed:@"origami_panel010024.png"],
[UIImage imageNamed:@"origami_panel010025.png"],
[UIImage imageNamed:@"origami_panel010026.png"],
[UIImage imageNamed:@"origami_panel010027.png"],
[UIImage imageNamed:@"origami_panel010028.png"],
[UIImage imageNamed:@"origami_panel010029.png"],
[UIImage imageNamed:@"origami_panel010030.png"],
[UIImage imageNamed:@"origami_panel010031.png"],
[UIImage imageNamed:@"origami_panel010032.png"],
[UIImage imageNamed:@"origami_panel010033.png"],
[UIImage imageNamed:@"origami_panel010034.png"],
[UIImage imageNamed:@"origami_panel010035.png"],
[UIImage imageNamed:@"origami_panel010036.png"],
[UIImage imageNamed:@"origami_panel010037.png"],
[UIImage imageNamed:@"origami_panel010038.png"],
[UIImage imageNamed:@"origami_panel010039.png"],
[UIImage imageNamed:@"origami_panel010040.png"],
[UIImage imageNamed:@"origami_panel010041.png"],
[UIImage imageNamed:@"origami_panel010042.png"],
[UIImage imageNamed:@"origami_panel010043.png"],
[UIImage imageNamed:@"origami_panel010044.png"],
[UIImage imageNamed:@"origami_panel010045.png"],
[UIImage imageNamed:@"origami_panel010046.png"],
[UIImage imageNamed:@"origami_panel010047.png"],
[UIImage imageNamed:@"origami_panel010048.png"],
[UIImage imageNamed:@"origami_panel010049.png"],
[UIImage imageNamed:@"origami_panel010050.png"],
[UIImage imageNamed:@"origami_panel010051.png"],
[UIImage imageNamed:@"origami_panel010052.png"],
[UIImage imageNamed:@"origami_panel010053.png"],
[UIImage imageNamed:@"origami_panel010054.png"],
[UIImage imageNamed:@"origami_panel010055.png"],
[UIImage imageNamed:@"origami_panel010056.png"],
[UIImage imageNamed:@"origami_panel010057.png"],
[UIImage imageNamed:@"origami_panel010058.png"],
[UIImage imageNamed:@"origami_panel010059.png"],
[UIImage imageNamed:@"origami_panel010060.png"],
[UIImage imageNamed:@"origami_panel010061.png"],
[UIImage imageNamed:@"origami_panel010062.png"],
[UIImage imageNamed:@"origami_panel010063.png"],
[UIImage imageNamed:@"origami_panel010064.png"],
[UIImage imageNamed:@"origami_panel010065.png"],
nil];
panel1Image.animationImages = panel1Frames;
panel1Image.animationDuration = 3.0;
panel1Image.animationRepeatCount = 1;
当按下UIButton时加载,无论如何都要加载图像吗?
此外,有没有办法让它只能一次播放一个动画?这会减少使用的内存量吗?
谢谢!
答案 0 :(得分:0)
你的问题是ios推迟实际加载图像,直到需要渲染它们为止。而不是你拥有的,创建一个名称数组,迭代它们,像现在一样创建一个图像,询问它的CGImage,然后使用它创建另一个保存在可变数组中的uiimage。如果这适用于你添加评论,那么有一个微妙的规模。
如果您担心总内存,可以将uiimages放在NSCache中。
如果您只想播放一个动画,则在播放其他按钮时将其设置为关闭。
编辑:如果你真的无法克服内存困扰,请创建一个演示项目,每个按钮按一个动画并将其发布到公共站点,然后通过参考项目更新原始问题。