Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ask iphone device orientation to refresh

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.

like image 967
bkbeachlabs Avatar asked Jul 11 '12 04:07

bkbeachlabs


2 Answers

Perhaps try..

[UIViewController attemptRotationToDeviceOrientation];

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

like image 54
anon_dev1234 Avatar answered Sep 26 '22 17:09

anon_dev1234


There are a few methods in UIViewController that you can override to catch the view-did-rotate event:

– willRotateToInterfaceOrientation:duration:
– willAnimateRotationToInterfaceOrientation:duration:
– didRotateFromInterfaceOrientation:

Do check the UIViewController class reference

like image 25
xingzhi.sg Avatar answered Sep 26 '22 17:09

xingzhi.sg