Hot fix of Orientation Problem on iOS 6

By walzer Posted 2012-09-23 14:28 Comments 5

Since iOS updated some orientation relatived methods, cocos2d-x games with v2.0.2 and before can’t be rendered to correct orientation.

I fixed it in this commit
You can update your games simply with the codes below:

  1. yougame/ios/ Change this line

    // Set RootViewController to window
    [window addSubview: viewController.view];


// Set RootViewController to window
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
    // warning: addSubView doesn't work on iOS6
    [window addSubview: viewController.view];
    // use this mehod on ios6
    [window setRootViewController:viewController];
  1. In yourgame/ios/, we used this method to deal with auto rotation before ios6

    // Override to allow orientations other than the default portrait orientation.

    • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return UIInterfaceOrientationIsLandscape( interfaceOrientation ); }

But this method is deprecated since iOS 6. Instead, we need to add 2 methods in

// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead of shouldAutorotateToInterfaceOrientation
- (NSUInteger) supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;

- (BOOL) shouldAutorotate {
    return YES;


  • Wriggler

    Thanks for the heads up Walzer.

    2012-09-24 08:42
  • johngg123

    Does this also address the Game Center authentication crash in iOS6 ? I believe a portrait view MUST be supported for Game Center to not crash.

    See here:\#731764

    2012-09-25 21:07
  • festival
    • (NSUInteger) supportedInterfaceOrientations will only be called when the App has a deployment version of iOS6 !

    Even when running on iOS6 device or compiled with iOS6 SDK (of course that must be done anyway).

    Setting a deployment target of i.e. iOS4.3 will use the deprecated method.

    2012-10-03 17:33
  • bulgasal

    My Game is compiled with ios 5.
    Then I don’t need those two hot fixes…?

    2012-10-03 18:20
  • nikhil

    [window setRootViewController:viewController]; is backward completable up to ios 4.0 :)

    2012-10-06 06:06

Copyright © 2010 - 2014 Support Email: