miałem ten sam problem przy użyciu Cocos2d 2.0
Moim problemem było to, że projekt ewoluował w ciągu kilku lat i obecnie prowadzone wzdłuż pewnych szczątkowych plików, takich jak RootViewController i UIViewController i MyRootViewController itp
Pracowali wtedy, ale wyraźnie podnieśli flagę z dzisiejszym komitetem ds. Przeglądu, ponieważ otrzymałem powiadomienie o odrzuceniu "Wszystkie aplikacje iPhone na iPadzie". Po głośnym krzyku i ostatecznym zaakceptowaniu porażki, uznałem, że polityka sprawia, że tworzenie iPhone'a z aplikacjami jest naprawdę trudne. Daj mi znać, jeśli się mylę.
Mimo, że byłem (i wciąż jestem) zaniepokojony tym, pomyślałem, że być może teraz mógłbym przynajmniej oczyścić projekt z bardziej eleganckim rozwiązaniem, które rozwiązuje podstawowy problem: rotacja urządzenia + rotacja treści. W końcu skorzystałem z czegoś z nowszego projektu, nad którym pracowałem i wydawało się bardziej eleganckie i faktycznie działało: po prostu dodaj MyNavigationController na szczyt mojego AppDelegate.
Dodałem poniższy kod. Jestem pewien, że można to poprawić. Proszę skomentuj, czy możesz go ulepszyć.
W rezultacie udało mi się usunąć stare pliki RootViewController i MyRootViewController, dzięki czemu łatwiej jest je zachować. Nigdy i tak nie zrozumiałem ich przeznaczenia. Dobry riddance!
Oto moje rozwiązanie do wyświetlania i dopasowywanie orientacji urządzenia + orientację treści:
w AppDelegate.h musiałem zadeklarować co robiłem:
// początku pliku
@ interfejs MyNavigationController: UINavigationController @end
// wewnątrz interfejsu AppDelegate.h
MyNavigationController * navController_;
// dole pliku przed @end
@property (tylko do odczytu) MyNavigationController * navController;
Oto kod, który działa na górze mojego 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
Oto dlaczego musiałem rozwiązać ten problem:
- potrzebowałem zarówno Krajobraz i trybie pionowym, aby wyświetlić różne sceny.
Oto kilka zrzutów ekranu, które opisują sytuację
próbowałeś uruchomić go na symulatorze iPad? Czy masz @ 2x obrazy? – Jamie