[英]iOS - UIImageView Animation receiving memory warning
我试图运行两个UImageView,它们具有多个动画数组,它们会根据用户的选择进行加载和动画处理。 例如,这是一种方法:
-(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.
我收到此消息后,加载的任何新动画都会使应用程序崩溃。 我在Instruments上运行它,但找不到任何泄漏,崩溃时输出没有任何帮助。
这里有内存问题吗? 我如何摆脱这个问题? 谢谢。
一些想法:
1)数组中加载的动画数量不得超过1个。 停止一个动画并准备开始另一个动画后,请删除第一个动画,并将观众看到的图像替换为应显示的单个图像。 如果您可以确定显示的确切图像(对此表示怀疑),则可以用单个图像替换阵列,并且该图像不会闪烁。
2)如果您无法执行1),请尝试直接使用Core Animation(为您做更多工作),然后自己制作动画。 这使您可以更好地控制内存使用情况(您可以在文件系统上缓存图像位图)。
3)使用Mac和AVFoundation或QTKit,从图像制作动画,然后创建一个开始和停止而不是图像序列的“电影”。 在这种情况下,您可以用电影对象替换捆绑包中的静态图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.