2012-04-12 63 views
8

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

我已经添加下列文件到我的应用程序:

为Default.png - (iPhone)

[email protected] - (iPhone的Retina)

默认画像〜iPad的.PNG - 总览

[email protected]~ipad.png - (iPad的视网膜)

当应用程序启动时,它似乎选择了正确的Default.png图像用于每个场合。然而,在我的AppDelegate我有一个简单的启动画面,使流畅的应用程序的加载和过渡到应用,做这样的事情:

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"]没有选择正确的文件为每个设备,我相信问题是文件名的-Portrait部分。

因此,作为一个快速的解决方案,我这样做:

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:@"[email protected]~ipad"]; 
    } 
    else { 
     splashView.image = [UIImage imageNamed:@"Default-Portrait~ipad"]; 
    } 
} 
else 
    splashView.image = [UIImage imageNamed:@"Default"]; 

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

+0

这是否看起来很有趣?这很有趣 – Krishnabhadra 2012-04-12 11:43:03

+0

尝试一些NSLogging,看看究竟发生了什么。 – 2012-04-12 12:34:38

+0

@rokjarc当你做一个简单的'[UIImage imageNamed:@“默认”]'时,你怎么能NSLog选择哪个文件? – mobius 2012-04-12 13:01:23

回答

4

对于官方信息在这里看看:App-Related Resources

对于启动映像使用此格式:

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

看起来你会使用会更好:

Default.png - (iPad) 

[email protected] - (iPad Retina) 

Default~iphone.png - (iPhone) 

[email protected]~iphone.png -(iPhone Retina) 

这应该即使简单地使用,也能给您适当的图像:

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

' - [UIImage imageNamed:]'不起作用 - 由于@ mobius突出显示,问题在于方向修改器。所以像Default〜ipad.png这样的东西可以工作,但Default-Portrait〜ipad.png不能和' - [UIImage imageNamed:]'一起工作(即使iPad在启动时确实会选择正确的图像)。 – 2013-05-02 06:05:49

0

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

 
App Launch (Default) Images 
<basename><usage_specific_modifiers><scale_modifier><device_modifier>.png 

Providing Launch Images for Different Orientations 
<basename><orientation_modifier><scale_modifier><device_modifier>.png 

Providing Launch Images for Custom URL Schemes 
<basename>-<url_scheme><scale_modifier><device_modifier>.png 
2

一旦我的通用应用加载完成后,我在一个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 
     // [email protected]~ipad.png 
     // Default-Portrait~ipad.png 
     // [email protected]~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 
      // [email protected] 
      launchImageName = [NSMutableString stringWithFormat:@"%@.png", launchImageName]; 
     } 
    } 
    UIImage *launchImage = [UIImage imageNamed:launchImageName];