问题
I'm building a cocos2d game which is supposed to be in portrait mode. I changed the RootViewController.m to portrait mode, and everything works fine, both on the simulator and on my iPad. However, when I run the game on my iPhone, it defaults back to landscape mode.
Any ideas on how to fix this?
Thanks.
回答1:
I have a better solution that will work 100%:
Replace all the stuff that was in the RootViewController.m / shouldAutorotateToInterfaceOrientation Method with following:
return ( UIInterfaceOrientationIsPortrait( interfaceOrientation ) );
And if I ever want to change the orientation during runtime / switching scene:
[[CCDirector sharedDirector] setDeviceOrientation:CCDeviceOrientationLandscapeLeft];
Note that Auto Rotation is now on longer supported
回答2:
in GameConfig.h:
use the director for autorotation
#if defined(__ARM_NEON__) || TARGET_IPHONE_SIMULATOR
#define GAME_AUTOROTATION kGameAutorotationCCDirector
instead of
#if defined(__ARM_NEON__) || TARGET_IPHONE_SIMULATOR
#define GAME_AUTOROTATION kGameAutorotationUIViewController
and in the AppDelegate.m
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
...
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
回答3:
Inside the RootViewController return false from the method below:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return false;
// other code...
}
回答4:
In RootViewController.m
return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) );
change this line to
return ( UIInterfaceOrientationIsPortrait( interfaceOrientation ) );
回答5:
in GameConfig.h:
For 1st and 2nd generation devices, value is set to kGameAutorotationNone, change it to kGameAutorotationUIViewController.
// ARMv6 (1st and 2nd generation devices): Don't rotate. It is very expensive
#elif __arm__
#define GAME_AUTOROTATION kGameAutorotationNone
来源:https://stackoverflow.com/questions/5987066/cocos2d-portrait-mode-not-working-on-iphone