Ho avuto lo stesso problema con Cocos2d 2.0
Il mio problema era che il progetto si è evoluto nell'arco di diversi anni e aveva portato con sé alcuni file ora rudimentali come RootViewController e UIViewController e MyRootViewController, ecc
Hanno lavorato in quel momento ma chiaramente avevano alzato una bandiera con il comitato di revisione di oggi perché ho ricevuto l'avviso di rifiuto "Tutte le app iPhone devono funzionare su iPad". Dopo aver urlato ad alta voce e aver finalmente accettato la sconfitta, ho pensato che la politica rendesse piuttosto difficile creare un'app solo per iPhone. Fammi sapere se mi sbaglio su questo.
Anche se ero (e sono ancora) turbato a riguardo, ho pensato che forse ora avrei potuto almeno ripulire il progetto con una soluzione più elegante che gestisse il problema di base: rotazione dei dispositivi + rotazione dei contenuti. Ho finito per utilizzare qualcosa di un progetto più recente su cui si stava lavorando e sembrava più elegante e funzionante: basta aggiungere MyNavigationController all'inizio del mio AppDelegate.
Ho aggiunto il codice qui sotto. Sono sicuro che può essere migliorato. Si prega di commentare se è possibile migliorare.
Come risultato, sono stato in grado di eliminare i vecchi file RootViewController e MyRootViewController così ora è più semplice da gestire. Non ho mai capito il loro scopo molto bene comunque. Buona liberazione!
Qui è la mia soluzione per la visualizzazione e la congruenza orientamento del dispositivo + orientamento del contenuto:
in AppDelegate.h ho dovuto dichiarare quello che stavo facendo:
// all'inizio del file
@ interfaccia MyNavigationController: UINavigationController @end
// all'interno dell'interfaccia AppDelegate.h
MyNavigationController * navController_;
// fine del file prima di @end
@property (sola lettura) * MyNavigationController navController;
Ecco il codice che funziona nella parte superiore del mio AppDelegate.m
@implementation MyNavigationController
// The available orientations should be defined in the Info.plist file.
// And in iOS 6+ only, you can override it in the Root View controller in the "supportedInterfaceOrientations" method.
// Only valid for iOS 6+. NOT VALID for iOS 4/5.
-(NSUInteger)supportedInterfaceOrientations {
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationPortrait) {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// [director_ pushScene: [IPAD scene]];
} else {
[[CCDirectorIOS sharedDirector] pushScene:[VerticalDisplayLayer scene]];
return UIInterfaceOrientationMaskPortrait;
}
} else if (orientation == UIDeviceOrientationLandscapeLeft) {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// [director_ pushScene: [IPAD scene]];
} else {
[[CCDirectorIOS sharedDirector] pushScene:[MainMenuScene scene]];
}
} else if (orientation == UIDeviceOrientationLandscapeRight) {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// [director_ pushScene: [IPAD scene]];
} else {
[[CCDirectorIOS sharedDirector] pushScene:[MainMenuScene scene]];
}
} else if (orientation == UIDeviceOrientationPortraitUpsideDown) {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
} else {
[[CCDirectorIOS sharedDirector] pushScene:[VerticalDisplayLayer scene]];
return UIInterfaceOrientationMaskPortraitUpsideDown;
}
} else {
//do nothing
}
return UIInterfaceOrientationMaskLandscape;
}
//this is the one for iOS 6
- (BOOL)shouldAutorotate {
//NSLog(@"MyNavigationController - should Rotate ToInterfaceOrientation ...");
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
// iPhone only
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
//NSLog(@"MyNavigationController - should Rotate iPhone");
if (orientation == UIDeviceOrientationPortrait) {
//NSLog(@"should Rotate iPhone orientation is Portrait");
[[CCDirectorIOS sharedDirector] pushScene:[VerticalDisplayLayer scene]];
return UIInterfaceOrientationMaskPortrait;
}
if (orientation == UIDeviceOrientationPortraitUpsideDown) {
//NSLog(@"should Rotate iPhone orientation is PortraitUpsideDown");
[[CCDirectorIOS sharedDirector] pushScene:[VerticalDisplayLayer scene]];
return UIInterfaceOrientationMaskPortraitUpsideDown;
}
if (orientation == UIDeviceOrientationLandscapeLeft) {
//NSLog(@"should Rotate iPhone orientation is Landscape Left");
return UIInterfaceOrientationMaskLandscape;
}
if (orientation == UIDeviceOrientationLandscapeRight) {
//NSLog(@"should Rotate iPhone orientation is Landscape Right");
return UIInterfaceOrientationMaskLandscape;
}
return TRUE;
}
//return UIInterfaceOrientationIsLandscape(interfaceOrientation);
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
//NSLog(@"MyNavigationController - should Rotate iPad");
return TRUE;
}
return TRUE;
}
// Supported orientations. Customize it for your own needs
// Only valid on iOS 4/5. NOT VALID for iOS 6.
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
// iPhone only
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
return TRUE;
//return UIInterfaceOrientationIsLandscape(interfaceOrientation);
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
return TRUE;
// iPad only
// iPhone only
//return UIInterfaceOrientationIsLandscape(interfaceOrientation);
return TRUE;
}
// This is needed for iOS4 and iOS5 in order to ensure
// that the 1st scene has the correct dimensions
// This is not needed on iOS6 and could be added to the application:didFinish...
-(void) directorDidReshapeProjection:(CCDirector*)director
{
if(director.runningScene == nil) {
// Add the first scene to the stack. The director will draw it immediately into the framebuffer. (Animation is started automatically when the view is displayed.)
// and add the scene to the stack. The director will run it when it automatically when the view is displayed.
[director runWithScene: [MainMenuScene scene]];
}
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
// Assuming that the main window has the size of the screen
// BUG: This won't work if the EAGLView is not fullscreen
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGRect rect = CGRectZero;
//NSLog(@"MyNavigationController - Will RotateToInterfaceOrientation ...");
if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
rect = screenRect;
} else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
rect.size = CGSizeMake(screenRect.size.height, screenRect.size.width);
}
CCDirector *director = [CCDirector sharedDirector];
CCGLView *glView = (CCGLView *)[director view];
glView.frame = rect;
}
@end
Ecco perché ho dovuto risolvere questo:
- avevo bisogno di entrambe le modalità Orizzontale e Verticale per visualizzare scene diverse.
Ecco alcuni screenshot che descrivono la situazione
Hai provato in esecuzione sul simulatore di iPad? Hai @ 2x immagini? – Jamie