iPhone、iPad开发之图片资源管理
来源:互联网 发布:数组和指针的区别 编辑:程序博客网 时间:2024/04/30 12:30
文件GGImageNameKey.h、GGImageNameKey.m用于管理图片的名字。由一个键值,根据是iPhone、iPad、横屏、竖屏等关联出一个图片的名字,从而实现图片名字资源的统一管理。
文件GGImageManageService.h、GGImageManageService.m用于管理图片资源,现在只有加载图片资源的功能。
// 文件GGImageNameKey.h begin
#import <Foundation/Foundation.h>
@interface UZImageNameKey : NSObject {
}
+ (NSDictionary *)imageNameDatas;
@end
// 这里定义图片资源的键值,有键值会关联出一个图片名
#define GGNextStepImage @"GGNextStepImage"
........... .............
// 文件GGImageNameKey.h end
// 文件GGImageNameKey. begin
#import "GGImageNameKey.h"
@implementation GGImageNameKey
+ (NSDictionary *)imageNameDatas {
/* 因为这个对象创建后放在自动释放池里,在下一次runLoop中会被销毁。
所以建议在程序运行中,该方法只调用一次,而且获取资源后,需要retain一份 */
NSDictionary *dict = nil;
dict = [NSDictionarydictionaryWithObjectsAndKeys:
// 以此为iPhone横屏、iPhone竖屏、iPad横屏、iPad竖屏对应的图片名字
[NSArrayarrayWithObjects:@"GGNextStepIphoneL.png",@"GGNextStepIphoneP.png",@"GGNextStepIpadL.png",@"GGNextStepIpadP.png",nil],
GGNextStepImage,
... ...
nil];
return dict;
}
@end
// GGImageNameKey.m end
// GGImageManageService.h begin
#import <Foundation/Foundation.h>
#import "GGImageNameKey.h"
// 获取图片名字
#define GGImageNameForKey(key) [GGImageManageService imageNameForKey:key]
// 加载图片
#define GGImageCacheForKey(key) [GGImageManageService imageCacheForKey:key]
#define GGImageForKey(key) [GGImageManageService imageForKey:key]
@interface GGImageManageService : NSObject {
NSDictionary *_datas; // 图片资源数据
NSInteger _index; // 需要获取的图片类型的索引
}
// 由键值获取一张图片名
+ (NSString *)imageNameForKey:(NSString *)key;
// 加载一张图片 注意:这种图片加载方式,图片是加载到iPhone系统缓存
+ (UIImage *)imageCacheForKey:(NSString *)key;
// 加载一张图片
+ (UIImage *)imageForKey:(NSString *)key;
// 关闭服务
+ (void)shutdownService;
@property (nonatomic,retain) NSDictionary *datas;
@property (nonatomic) NSInteger index;
@end
// GGImageManageService.m end
// GGImageManageService.m begin
#import "GGImageManageService.h"
#import "GGImageNameKey.h"
static GGImageManageService *sGGImageManageService =nil;
@implementation UZImageManageService
@synthesize datas = _datas;
@synthesize index = _index;
- (id)init {
if (self = [superinit]) {
_datas = [GGImageNameKeyimageNameDatas];
[_datasretain];
NSInteger orientation = [[UIApplication sharedApplication] statusBarOrientation]; // 获取屏幕方向
if (orientation ==UIInterfaceOrientationLandscapeLeft || orientation ==UIInterfaceOrientationLandscapeRight) {
_index =0;
}
else {
_index =1;
}
if (0/**设备为iPad */) {
_index = _index +2;
}
}
returnself;
}
+ (void)shutdownService {
SAFE_RELEASE(sGGImageManageService);
}
+ (void)createSelf {
if (sGGImageManageService ==nil) {
sGGImageManageService = [[GGImageManageServicealloc]init];
}
}
+ (NSString *)imageNameForKey:(NSString *)key {
[GGImageMangeServicecreateSelf];
return [[sGGImageManageService.datasobjectForKey:key]objectAtIndex:GGImageMangeService.index];
}
+ (UIImage *)imageForKey:(NSString *)key {
NSString *path = [[NSBundlemainBundle]pathForResource:[GGImageMangeServiceimageNameForKey:key] ofType:nil];
return [UIImageimageWithContentsOfFile:path];
}
+ (UIImage *)imageCacheForKey:(NSString *)key {
return [UIImageimageNamed:[GGImageMangeServiceimageNameForKey:key]];
}
- (void)dealloc {
SAFE_RELEASE(_datas);
[superdealloc];
}
@end
// GGImageMangeService end
说明:应用程序退出时,需要调用[GGImageMangeService shutdownService];
- iPhone、iPad开发之图片资源管理
- iPhone、iPad开发之图片资源管理
- ipad开发开发之区别于iphone
- ipad开发开发之区别于iphone
- ipad开发开发之区别于iphone
- ipad开发开发之区别于iphone
- ipad开发开发之区别于iphone
- iphone/ipad开发之UITableView的方法
- iphone ipad 开发视频教程
- iphone/ipad保存图片问题
- ipad,iphone启动图片命名
- iphone/ipad 图片位置说明
- ipad iphone 异步图片加载
- ipad,iphone启动图片命名
- Week summary --iphone/ipad 开发应用培训之二
- IOS(iphone,ipad,itouch)开发 之 屏幕旋转
- iPhone iPad iOS 开发环境 之 XCODE 4.1 on Lion
- (iPhone/iPad开发)适配Xcode 5+iOS 7之statusBar
- 用JSP实现的商城购物车模块
- linux-2.6.30平台下移植DM9000网卡驱动到TQ2440
- CURL 模拟提交
- 如何查看端口是否被占用,及被哪个程序占用
- 创业公司: 首席产品设计师的最低要求
- iPhone、iPad开发之图片资源管理
- style.left 与 style.top 在 IE和FireFox的兼容问题
- Ubuntu12.04 安装与卸载jdk1.6
- 关于在内部类中启动一个Android Intent的疑惑
- hdu1698 Just a Hook
- cocoa下的扩展日志输出例程
- php100视频之Ajax+PHP快速上手及应用(一)【第48讲】
- 用Autohotkey实现分屏
- linux内核下载地址