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?
Than开发者_运维知识库ks.
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
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];
Inside the RootViewController return false from the method below:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return false;
// other code...
}
In RootViewController.m
return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) );
change this line to
return ( UIInterfaceOrientationIsPortrait( interfaceOrientation ) );
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
精彩评论