News

Hot fix of Orientation Problem on iOS 6

By walzer@cocos2d-x.org Posted 2012-09-23 14:28

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 https://github.com/walzer/cocos2d-x/commit/70f1360ac2f0397ae8e32422a3be1d232bebd410
You can update your games simply with the codes below:

  1. yougame/ios/AppController.mm. Change this line

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

to

// Set RootViewController to window
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
{
    // warning: addSubView doesn't work on iOS6
    [window addSubview: viewController.view];
}
else
{
    // use this mehod on ios6
    [window setRootViewController:viewController];
}
  1. In yourgame/ios/RootViewController.mm, 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 RootViewController.mm

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

- (BOOL) shouldAutorotate {
    return YES;
}

Comments

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.