2013-03-16 72 views
1

我试图运行两个UImageViews有多个动画数组,他们根据用户的选择加载和动画。例如,下面是一个方法:iOS - UIImageView动画接收内存警告

-(void)initiateAnimations { 

nullAnimation = [NSArray arrayWithObjects: 

      [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0002" ofType:@"png"]], 
      [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0003" ofType:@"png"]], 
      [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0004" ofType:@"png"]], 
      [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0005" ofType:@"png"]], 
      [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0006" ofType:@"png"]], 
      [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0007" ofType:@"png"]], 
      [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0008" ofType:@"png"]], 
      [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0009" ofType:@"png"]], 
      [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0010" ofType:@"png"]], nil]; 
} 

这里是一个IBAction调用动画制作方法:

-(IBAction)nullani { 
player.animationImages = nullAnimation; 
player.animationDuration = 0.50; 
player.animationRepeatCount = 1; 
[player startAnimating]; 
} 

这一切运作良好,在第一,但请记住,我有大约5-6其他大致具有相同尺寸图像的动画数组。他们不是很大,范围从12-80k.png文件。我收到此消息,任何新的动画加载会崩溃的应用程序后

2013-03-16 01:34:44.438 [3316:907] Received memory warning.

:当我尝试了几次后,动画,我在输出recieving此错误。 我通过Instruments运行它,无法找到任何泄漏,并且输出在崩溃时不会给我带来任何影响。

这里是否有任何内存问题?我如何摆脱这个问题?谢谢。

+1

图像有多大?磁盘上的大小不能以kb为单位,如.png文件。像素?请记住,要显示图像,他们需要解压缩,所以它可能没有太多关于12-80k大小。这些全屏图像? – Nate 2013-03-16 08:50:42

+0

请记住,泄漏的内存不是您内存不足的唯一方法。你可以使用太多。仪器告诉你有关内存使用情况的内容?每次启动动画时,您使用了多少个字节? – jrturton 2013-03-16 08:55:40

+0

@Nate正常大小是800x800,视网膜1600x1600。它大部分是空白的,主要内容大约是75x400,因为我有动画增长/缩小/扩展。 800x800就像一个舞台。 – nworksdev 2013-03-16 08:57:02

回答

0

一些想法:

1)从不超过1个动画加载到阵列。一旦您停止一个动画并准备好开始另一个动画,请删除第一个动画,并将查看器看到的图像替换为应显示的单个图像。如果您可以确定显示的确切图像(并且怀疑这一点),那么您可以用单个图像替换该阵列,并且图像不会闪烁。 2)如果你不能做1),那么直接尝试使用核心动画(为你更多的工作),并自己做动画。这使您可以更好地控制内存使用情况(可以在文件系统上缓存图像位图)。

3)使用Mac和AVFoundation或QTKit,从图像制作动画,然后创建一个“电影”,您可以开始和停止,而不是图像序列。在这种情况下,您可以用电影对象替换包中的静态图像。

+0

请先生@nworksdev ..你还没有接受..任何“stackoverflow的”答案.. :( – TonyMkenu 2013-03-29 09:37:49