简体   繁体   English

iOS-UIImageView Animation收到内存警告

[英]iOS - UIImageView Animation receiving memory warning

I am attempting to run two UImageViews that have multiple arrays of animations they load and animate based on a selection the user makes. 我试图运行两个UImageView,它们具有多个动画数组,它们会根据用户的选择进行加载和动画处理。 For example, here is one method: 例如,这是一种方法:

-(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];
}

And here is an IBAction calling the animation method: 这是一个调用动画方法的IBAction

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

It all works well at first, but keep in mind i have about 5-6 other arrays of animations roughly with the same size images. 最初一切都很好,但是请记住,我还有大约5-6个其他动画数组,它们的图像大小基本相同。 They arent huge, ranging from 12-80k .png files. 它们不大,范围从12-80k .png文件。 When i attempt to animate after a few times, I am recieving this error in the output: 几次尝试制作动画时,我在输出中收到此错误:

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

After i receive this message, any new animation loaded will crash the app. 我收到此消息后,加载的任何新动画都会使应用程序崩溃。 I ran it through Instruments and was unable to find any leaks, and the output gives me nothing upon crash. 我在Instruments上运行它,但找不到任何泄漏,崩溃时输出没有任何帮助。

Is there any memory issues here? 这里有内存问题吗? how can i get rid of this issue? 我如何摆脱这个问题? thanks. 谢谢。

Some ideas: 一些想法:

1) Never have more than 1 animation loaded into an array. 1)数组中加载的动画数量不得超过1个。 Once you stop one animation, and are ready to start another, delete the first animation and replace the image the viewer sees with the single image that should be showing. 停止一个动画并准备开始另一个动画后,请删除第一个动画,并将观众看到的图像替换为应显示的单个图像。 If you can determine the exact image that was showing (and am doubtful of this) then you can replace the array with a single image and the image will not flicker. 如果您可以确定显示的确切图像(对此表示怀疑),则可以用单个图像替换阵列,并且该图像不会闪烁。

2) If you cannot do 1), then try using Core Animation directly (more work for you), and do the animation yourself. 2)如果您无法执行1),请尝试直接使用Core Animation(为您做更多工作),然后自己制作动画。 This gives you more control over memory usage (you could cache image bitmaps on the file system). 这使您可以更好地控制内存使用情况(您可以在文件系统上缓存图像位图)。

3) Using a Mac and AVFoundation or QTKit, make an animation from images, then create a "movie" that you start and stop instead of the image sequence. 3)使用Mac和AVFoundation或QTKit,从图像制作动画,然后创建一个开始和停止而不是图像序列的“电影”。 In this case you'd replace the static images in the bundle with movie objects. 在这种情况下,您可以用电影对象替换捆绑包中的静态图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM