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:
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.
Perhaps try..
[UIViewController attemptRotationToDeviceOrientation];
In viewDidLoad
or viewWillAppear
, that should make it attempt an orientation change
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With