Ios – ask iphone device orientation to refresh

iosiphoneorientationrotation

I'm creating a puzzle game for the iphone. All of my menus, etc are only in the portrait orientation, but my gameplay can be in either portrait or landscape.

So when I'm in the menu and the device is being held in landscape, then when I go to the gameplay viewcontroller, it does the layout with the landscape coordinates, but the screen is still actually oriented portrait-wise:

enter image description here

I want to force the device to re-orient the screen before I do the layout. How do I do that?

right now I'm testing for device orientation like this:

- (void) viewDidLoad {
    .
    .
    .

   if (!UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation])) {
      // Run Portrait Layout
   }
   else {
      // Run Landscape Layout
   }
}

So I know that the device is returning an orientation of landscape, but the screen is still oriented portrait for some reason.

Best Answer

Perhaps try..

[UIViewController attemptRotationToDeviceOrientation];

In viewDidLoad or viewWillAppear, that should make it attempt an orientation change