2012-04-12 13 views
8

Sto sviluppando un'applicazione utilizzando iOS 5.1 e sto riscontrando un comportamento strano con i file default.png.iOS 5.1 e Default.png

ho aggiunto i seguenti file alla mia domanda:

Default.png - (iPhone)

[email protected] - (iPhone Retina)

Default-Portrait ~ ipad .png - (iPad)

[email protected]~ipad.png - (iPad Retina)

All'avvio dell'applicazione sembra che selezioni l'immagine Default.png corretta da utilizzare per ogni occasione. Tuttavia nel mio AppDelegate Ho una semplice schermata di avvio per rendere più agevole il caricamento dell'applicazione e la transizione verso l'applicazione, facendo qualcosa di simile:

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]; 

Tuttavia il [UIImage imageNamed:@"Default"] a sua volta non selezionare il file corretto per ogni dispositivo e credo che il problema sia la parte -Portrait del nome file.

Così come una soluzione rapida che ho fatto questo:

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"]; 

È questo come dovrei fare questo? Ti sembra divertente?

+0

Ti sembra divertente? è divertente – Krishnabhadra

+0

Prova qualche NSLogging per vedere cosa sta succedendo esattamente. –

+0

@rokjarc Come si può NSLog quale file viene selezionato dall'SDK quando si esegue un semplice '[UIImage imageNamed: @" Default "]'? – mobius

risposta

4

Per informazioni ufficiali qui un'occhiata a: App-Related Resources

Per le immagini di lancio utilizzare questo formato:

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

Sembra che sarebbe meglio utilizzare:

Default.png - (iPad) 

[email protected] - (iPad Retina) 

Default~iphone.png - (iPhone) 

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

Questo dovrebbe darti un'immagine corretta anche se usando semplicemente:

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

'- [UIImage imageNamed:]' non funziona - come evidenziato da @mobius, il problema riguarda il modificatore di orientamento. Quindi qualcosa come Default ~ ipad.png funzionerà ma Default-Portrait ~ ipad.png non funziona con '- [UIImage imageNamed:]' (anche se al momento del lancio l'iPad riprende l'immagine giusta). –

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

volta che il mio universale applicazione ha terminato il caricamento, ho visualizzare una copia della schermata di avvio in un UIImageView e poi dissolvenza fuori, per dare una transizione dolce tra il lancio e l'applicazione di essere pronto. Ecco il codice che uso per determinare quale immagine utilizzare:

// 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]; 
Problemi correlati