在iphone / ipad通用应用程序中管理图像

我只是好奇人们用什么方法动态地在他们的通用iPhone / iPad应用程序中使用更大或更小的图像。

我创建了一个大的测试图像,我试着缩小(使用cocos2d)0.46875。 在iPhone 4.0模拟器中查看后,我发现结果非常糟糕......粗糙的像素边缘等等。另外,当iPhone用户不需要它们时加载巨大的图像文件是非常蹩脚的。

所以我想我可能要做的就是保存每个精灵的两个版本......大的(对于iPad侧)和小的(对于iPhone / iPod Touch),然后检测用户的设备并像这样吐出适当的精灵:


NSString *deviceType = [UIDevice currentDevice].model;
CCSprite *test;
if([deviceType isEqualToString:@"iPad"]) {
  test = [CCSprite spriteWithFile:@"testBigHuge.png"];
} else {
  test = [CCSprite spriteWithFile:@"testRegularMcTiny.png"];
}
[self addChild: test];

你们是怎么做到的? 我宁愿避免像这样的陈述散布所有的代码。 我也想避免使用.xib文件,因为它是基于OpenGL的应用程序。

谢谢!


我写了一个小小的助手thingy:


#define deviceFile(file, ext) 
  ([[UIDevice currentDevice].model rangeOfString:@"iPad"].location != NSNotFound ? 
    [NSString stringWithFormat:@"%@-iPad.%@", file, ext] : 
    [NSString stringWithFormat:@"%@.%@", file, ext])

用法:


// outputs either "test.png" or "test-iPad.png" depending on the user's device
CCSprite *test = [CCSprite spriteWithFile:deviceFile(@"test", @"png")];

始终用“大”或“小”命名每个图像,但保留其他名称与等效图像相同。

在某个地方,您可以在启动时设置一个全球范围值为@“Large”或@“Small”的值。

在某处,有一个方法将采用通用名称字符串并插入全局大小说明符。

@interface CCSprite (MyProject)
+(id) spriteWithSizedFile:(NSString *)inName;
@end

@implementation CCSprite(MyProject)
+(id) spriteWithSizedFile:(NSString *)inName {
  return [CCSprite spriteWithFile:[gSizeSpecifier stringByAppendingString:inName]];
}
@end

这可能比CCSprite更好。 这纯粹是一个例子。


#define M_IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
and make a function like this

   +(id)BooL
{
   if(M_IS_IPAD)
  {
      return true;
  }
  else
  {
    return false;
  }

}

在任何地方使用此:)并相应地更改图像的ipad或ipod ....

问候:shauket

链接地址: http://www.djcxy.com/p/95775.html

上一篇: managing images in an iphone/ipad universal app

下一篇: xcode: convert iphone to ipad issue