2012-04-12 70 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];