2012-10-02 10 views
28

Questo errore non ha senso, come l'orientamento preferito UIInterfaceOrientationLandscapeRight viene restituito dall'orientamento supportatopreferredInterfaceOrientationForPresentation deve restituire un orientamento interfaccia supportata

//iOS6 

-(BOOL)shouldAutorotate 
{ 
    return NO; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return (UIInterfaceOrientationLandscapeRight | UIInterfaceOrientationLandscapeLeft); 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationLandscapeRight; 
} 

errore:

terminazione app causa eccezione non identificata 'UIApplicationInvalidInterfaceOrientation', motivo: 'preferredInterfaceOrientationForPresentation deve restituire un orientamento di interfaccia supportato !'

risposta

52

Il codice dovrebbe essere simile a questa:

-(BOOL)shouldAutorotate 
{ 
    return NO; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationLandscapeRight; 
} 

Inoltre, assicurarsi che nel vostro Info.plist aver impostato gli orientamenti corretti per App perché ciò che si restituisce da supportedInterfaceOrientations viene intersecato con lo Info.plist e se non riesce a trovarne uno comune, si otterrà quell'errore.

+0

Sto trovando questo per provocarmi dolore! Dispongo di un codice di visualizzazione del ViewController universale per l'app e uso il test del codice sopra per l'idioma dell'utente. l'ipad deve essere solo orizzontale e il ritratto iphone per tutti quelli che devono essere panoramici. Non riesco a ottenere questo per fornire gli orientamenti corretti a – user7865437

+3

Si noti che è la parte "Maschera" di "UIInterfaceOrientationMaskLandscape" che è la parte importante di questa risposta. L'utente del poster originale ha sbagliato enum nel suo metodo. Sembra un po 'sciocco che Apple abbia creato un nuovo set di enum/opzioni per questo metodo che porta le persone a fare questo semplice errore - inoltre Xcode non fornisce nemmeno il controllo del compilatore perché il metodo restituisce NSUInteger. –

+1

@lms, La mia intera applicazione dovrebbe supportare solo per la modalità Ritratto eccetto una vista (che deve supportare Landscape). In Plist ho impostato l'orientamento solo per Portrait e ho scritto sopra il codice in cui voglio cambiare l'orientamento per Landscape. Ma sta dando sia UIInterfaceOrientationLandscapeRight o UIInterfaceOrientationLandscapeLeft. Ma voglio sia a mio avviso. Puoi sapere come posso ottenerlo. –

8

Queste sono le enumerazioni errate per supportedInterfaceOrientations. È necessario utilizzare UIInterfaceOrientationMaskLandscapeLeft, (maschera nota la parola nel mezzo), ecc

14

supportedInterfaceOrientations viene chiamato solo se shouldAutorotate è impostato su YES

- (BOOL)shouldAutorotate 
{ 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationLandscapeRight; 
} 

L'approccio più semplice per me, è solo per impostare il Info.plist

info.plist

Se vi piace per sostenere iOS 5 usa questo codice nei tuoi controller di visualizzazione.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
return UIInterfaceOrientationIsLandscape(interfaceOrientation); 
} 
1

dalla documentazione:

-(NSUInteger)supportedInterfaceOrientations { 

    return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft; 
} 

Si noti che l'orientamento corretto è "Mask"! Hai provato questo?

Problemi correlati