我目前正在使用UIImageView
根据用户按下的按钮设置一系列图像的动画。我有大约5组不同的图像,我在NSArrays
中创建了这些图像,例如:
-(void)initiateAnimations {
punchani = [NSArray arrayWithObjects:
[UIImage imageNamed:@"punch0001.png"],
[UIImage imageNamed:@"punch0002.png"],
[UIImage imageNamed:@"punch0003.png"],
[UIImage imageNamed:@"punch0004.png"],
[UIImage imageNamed:@"punch0005.png"],
[UIImage imageNamed:@"punch0006.png"],
[UIImage imageNamed:@"punch0007.png"],
[UIImage imageNamed:@"punch0008.png"],
[UIImage imageNamed:@"punch0009.png"],
[UIImage imageNamed:@"punch0010.png"],
[UIImage imageNamed:@"punch0011.png"],
[UIImage imageNamed:@"punch0012.png"],nil];
}
然后我使用标准动画代码循环它们一次:
player.animationImages = punchani;
player.animationDuration = 0.50;
player.animationRepeatCount = 1;
[player startAnimating];
然而,当我将越来越多/不同的图像加载到UIImageView
时,我最终会得到一个内存警告输出如下:(用'appname'替换我的实际可执行文件)
2013-03-15 20:52:23.065 AppName[2080:907] Received memory warning.
我知道这可能会发生,但ARC禁止我发布阵列。我该如何解决这个漏洞?感谢
答案 0 :(得分:4)
UIImage imageNamed:缓存图像并按照自己的计划释放内存。使用
+ (UIImage *)imageWithContentsOfFile:(NSString *)path
直接加载内存
Try this answer as well.动画结束后删除图像数组