In my view controller, I implement two methods for controlling interface orientation:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOr
I know this sounds pretty elementary, but I was wracking my brain to figure out orientation issues while testing on my iPhone - I had the physical auto lock mode in Portrait mode - so nothing I changed programmatically mattered - thought this should be troubleshooting step number 1!
- (BOOL) shouldAutorotate {
return YES;
}
// for landscape
- (NSInteger) supportedInterfaceOrientations {
return (1 << UIInterfaceOrientationLandscapeLeft) |
(1 << UIInterfaceOrientationLandscapeRight);
}
As noted above, check out the mask values for specific orientations : UIInterfaceOrientationMask values.UIInterfaceOrientationMask
Two points:
Your error message makes complete sense because it makes no sense to use UIInterfaceOrientationPortrait
as a return value from supportedInterfaceOrientations
, which is returning a bit mask. Use one of the UIInterfaceOrientationMask values.
You seem to be concerned that if you use the proper UIInterfaceOrientationMaskPortrait
, that iOS doesn't appear to call shouldAutorotate
. It may only call shouldAutorotate
if, having considered the physical device's physical orientation and the app's current orientation against the supportedInterfaceOrientations
that a rotation might be needed. Why should it check shouldAutorotate
if it concludes that the device is in an acceptable orientation already?
See supportedInterfaceOrientations and Handling View Rotations for more information.
In order to change the orientation setting, select menu Targets->Summary-> Supported Device Orientations and change as following.
If the buttons for the orientation are dark then that means you have selected it as one of the orientation.
rather than using an integer to declare the orientation why don't you use a bool and plug in a if statement in there to detect whatever orientation you want. here is a example code that i hope would help you:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
return YES;
}
if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
return YES;
}
return NO;
}
you can add all of the orientations in the if statement and it should work just fine. adrian
Edit:
and if you want to have an option for ios 6 the below code should work just fine for you.
- (BOOL) shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
you can change just about all the supported orientations with this in ios 6. happy coding
EDIT 1:
to rotate only certain viewcontrollers
in a certain way, just use the ios 6 code that i posted above in all viewcontrollers
. here are the steps:
in the project level where all four internfaceorientations
are located, go ahean and turn everything off so app would go to default.
implement the ios 6 code that i supplied in all viewcontrollers
.
shouldautorotate
method.this should do the trick for you. happy coding