IOS开发之——图片的内存优化

一 概述

创建Image的方式有两种:

  • UIImage *image=[UIImage imageNamed:imageName]—内存由系统管理
  • UIImage *image=[UIImage imageWithContentsOfFile:path]—开发者自己管理(优化)
imageName(324M)imageWithContentsOfFile(19M)

二 查看打包后的app文件

点击Xcode——>Preference,打开设置对话框

选中Locations菜单栏,点击Derved Data,打开包数据文件夹

找到当前应用的app

在app上右键,显示包内容,查看app的包信息

三 两种方式资源存放和获取方式

3.1 imageName方式

资源存放位置
  • Assets.xcassets:资源文件夹
  • 任意的图片文件夹:如Animations
imageName获取Image方式
UIImage *image=[UIImage imageNamed:@“eat_001.jpg”];

3.2 imageWithContentsOfFile

supporting files(bundle文件)

新版本不支持supporting files文件打包后,直接放到app的包目录下

存放位置
  • 直接拖放到项目根目录下(如Animations文件夹)
imageWithContentsOfFile获取Image方式
 NSString *imageName=[NSString stringWithFormat:@"Animations/Eat/%@_%02d.jpg",@"eat",i];
 NSString *path=[[NSBundle mainBundle]pathForResource:imageName ofType:nil];
 UIImage *image=[UIImage imageWithContentsOfFile:path];

四 内存优化(imageWithContentsOfFile)

4.1 优化方式一

[self performSelector:@selector(clearup) withObject:nil afterDelay:self.tom.animationDuration];

-(void)clearup
{
    NSLog(@"%s",__func__);
    self.tom.animationImages=nil;
}

4.2 优化方式二

[self.tom performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.tom.animationDuration];

五 参考

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值