hatte ich das gleiche Problem Cocos2d betrug 2,0
Mein Problem mit, dass das Projekt über mehrere Jahre entwickelt hatte und entlang einiger jetzt vestigial Dateien wie RootViewController und UIViewController und MyRootViewController getragen hatte, usw.
Sie arbeiteten zu der Zeit, hatten aber mit dem heutigen Review-Komitee eine Fahne gehisst, weil ich die Ablehnungsmitteilung "All iPhone apps muss auf dem iPad arbeiten" erhalten habe. Nachdem ich laut geschrien und schließlich eine Niederlage akzeptiert hatte, dachte ich, dass es mit dieser Richtlinie ziemlich schwer ist, eine App nur für das iPhone zu entwickeln. Lass es mich wissen, wenn ich falsch liege.
Obwohl ich (und immer noch) darüber beunruhigt bin, dachte ich, jetzt könnte ich das Projekt zumindest mit einer eleganteren Lösung aufräumen, die das Grundproblem behandelt: Gerätedrehung + Inhaltsrotation. Ich benutzte etwas aus einem neueren Projekt, an dem gearbeitet wurde und das eleganter aussah und tatsächlich funktionierte: einfach MyNavigationController oben auf meinem AppDelegate hinzufügen.
Ich habe den folgenden Code hinzugefügt. Ich bin mir sicher, dass es verbessert werden kann. Bitte kommentieren Sie, wenn Sie es verbessern können.
Als Ergebnis konnte ich die alten RootViewController und MyRootViewController Dateien löschen, so dass es jetzt einfacher zu pflegen ist. Ich habe ihren Zweck sowieso nie gut verstanden. Gute Riddance!
Hier ist meine Lösung für die Anzeige und Geräteausrichtung + inhaltliche Ausrichtung passend:
in AppDelegate.h musste ich erklären, was ich tat:
// Anfang der Datei
@ Schnittstelle MyNavigationController: UINavigationController @end
// innerhalb AppDelegate.h Schnittstelle
MyNavigationController * navController_;
// Ende der Datei vor @end
@property (Read-only) MyNavigationController * NavController;
Hier ist der Code, der oben auf meinem AppDelegate funktioniert.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
Hier ist, warum ich dieses Problem zu lösen hatte:
- ich sowohl Landschafts- und Portrait-Modus benötigt, um verschiedene Szenen angezeigt werden soll.
Hier sind einige Screenshots, die die Situation beschreiben
Haben Sie versucht, es auf dem iPad Simulator läuft? Hast du @ 2x Bilder? – Jamie