Objective-c using UIInterfaceOrientationMask to control orientation

I have an app with 4 viewcontrollers. One must be presented only in landscape mode. The other 3 can be either landscape or portrait.

In my Deployment Information area, Device Orientation, I have Upside Down, Landscape Left, and Landscape Right checked. In Info.plist I have 3 supported Interface Orientations: Landscape Left, Landscape Right, and Portrait Top Home Button.

In my view controller where I want ONLY landscape I have:
-(BOOL) shouldAutorotate{ return YES; }

-(UIInterfaceOrientationMask) supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeLeft+UIInterfaceOrientationMaskLandscapeRight;
}

In the other 3 view controllers I have:
-(BOOL) shouldAutorotate{ return YES; }

-(UIInterfaceOrientationMask) supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}

With all of these settings: 1) The view that should only be in landscape is only in landscape, so that’s good. 2) The other 3 views can be shown in landscape left, landscape right and portrait mode with the button at the top. 3) When I try to rotate the screen in the other portrait position it doesn’t rotate.

So, I change the Deployment page or the Info.plist page to include that 4th choice that isn’t checked. The result is that the 3 other views rotate ok, but the landscape mode view now rotates into portrait.

What do I have to do to get my first view landscape only and the other 3 to rotate any way?

UIInterfaceOrientationMaskLandscapeLeft+UIInterfaceOrientationMaskLandscapeRight

This is wrong. You need to use the bitwise OR to give the correct orientations:

UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight

Adding the numbers will give you a result that, by the look of it, includes the portrait orientation.

(Edit) Actually, this is probably nonsense. A proper bitmask would make adding the same as or-ing, so the problem must be elsewhere in your project. Sorry.

1 Like