IOS开发之——图片的内存优化
生活随笔
收集整理的這篇文章主要介紹了
IOS开发之——图片的内存优化
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一 概述
創建Image的方式有兩種:
- UIImage *image=[UIImage imageNamed:imageName]—內存由系統管理
- UIImage *image=[UIImage imageWithContentsOfFile:path]—開發者自己管理(優化)
二 查看打包后的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];五 參考
- iOS 把圖片資源打包成bundle
總結
以上是生活随笔為你收集整理的IOS开发之——图片的内存优化的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 全球及中国环绕声扬声器行业投资前景预测与
- 下一篇: MySQL时间戳转换