iOS 5.1和Default.png

我正在开发一个应用程序使用iOS 5.1,我遇到了一些奇怪的行为与default.png文件。

我已将以下文件添加到我的应用程序中:

Default.png – (iPhone)

Default@2x.ping – (iPhone Retina)

Default-Portrait〜ipad.png – (iPad)

Default-Portrait@2x~ipad.png – (iPad Retina)

当应用程序启动它似乎select正确的Default.png图像用于每个场合。 然而,在我的AppDelegate中,我有一个简单的启animation面,使应用程序的加载和向应用程序的转换变得更加平滑,如下所示:

UIImageView *splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,window.frame.size.width, window.frame.size.height)]; splashView.image = [UIImage imageNamed:@"Default"]; [window addSubview:splashView]; [window bringSubviewToFront:splashView]; 

然而, [UIImage imageNamed:@"Default"]反过来不会为每个设备select正确的文件,我相信问题是文件名的-Portrait部分。

所以作为一个快速的解决scheme,

 if( ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) ) { // Force the image used by ipads if( [[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2.0) { splashView.image = [UIImage imageNamed:@"Default-Portrait@2x~ipad"]; } else { splashView.image = [UIImage imageNamed:@"Default-Portrait~ipad"]; } } else splashView.image = [UIImage imageNamed:@"Default"]; 

这是我应该怎么做? 这看起来很有趣吗?

有关官方信息,请参阅: 应用程序相关资源

对于启动图像使用这种格式:

 <basename><orientation_modifier><scale_modifier><device_modifier>.png 

看起来你会更好使用:

 Default.png - (iPad) Default@2x.png - (iPad Retina) Default~iphone.png - (iPhone) Default@2x~iphone.png -(iPhone Retina) 

这应该给你适当的形象,即使使用简单:

 splashView.image = [UIImage imageNamed:@"Default"]; 

一旦我的通用应用程序加载完成后,我会在UIImageView显示一个启动屏幕的副本,然后将其淡出,以便在启动和应用程序准备就绪之间轻松转换。 以下是我用来确定要使用哪个图像的代码:

  // choose the correct launch image for orientation, device and scale NSMutableString *launchImageName = [[NSMutableString alloc] initWithString:@"Default"]; BOOL isPad = ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ); if( isPad ) { BOOL isLandscape = UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]); NSString *imageOrientation = (isLandscape) ? @"Landscape" : @"Portrait"; BOOL isRetina = ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2.0); NSString *scaleString = (isRetina) ? @"@2x" : @""; // Default-Landscape~ipad.png // Default-Landscape@2x~ipad.png // Default-Portrait~ipad.png // Default-Portrait@2x~ipad.png launchImageName = [NSMutableString stringWithFormat:@"%@-%@%@~ipad.png", launchImageName, imageOrientation, scaleString ]; } else { if( CGRectGetHeight(self.view.frame) > 480.f) { // Default-568h.png launchImageName = [NSMutableString stringWithFormat:@"%@-568h.png", launchImageName]; } else { // Default.png // Default@2x.png launchImageName = [NSMutableString stringWithFormat:@"%@.png", launchImageName]; } } UIImage *launchImage = [UIImage imageNamed:launchImageName]; 

http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/App-RelatedResources/App-RelatedResources.html

应用程序启动(默认)图像
 <基本名称> <usage_specific_modifiers> <scale_modifier> <device_modifier> .PNG

为不同的方向提供图像
 <基本名称> <orientation_modifier> <scale_modifier> <device_modifier> .PNG

为自定义URLscheme提供启动映像
 <基名>  -  <url_scheme> <scale_modifier> <device_modifier> .PNG