I have looked at documentation but cannot find why sometimes the word mask is inserted and sometimes not.
what is the difference between UIInterfaceOrientationMaskPortrait and UIInterfaceOrientationPortrait
Asked
Active
Viewed 6,109 times
1 Answers
5
UIInterfaceOrientationMask
is used by iOS 6's
-[UIViewController supportedInterfaceOrientations]
method (docs here), which is a bitmask of all the orientations your view controller will take, called by the sdk. The following is an example implementation:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape; // supports both landscape modes
}
This is in contrast to the pre iOS 6 (now deprecated, docs here) method:
-[UIViewController shouldAutorotateToInterfaceOrientation:]
which gave you a UIInterfaceOrientation
enum value, to which you tested against with something like:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
Note that you still get the UIInterfaceOrientation
enum in the didRotate method as well as the interfaceOrientaiton
property, which can be useful at other times. The mask is only used when the sdk is deciding whether to rotate your view controller or not.
Question for others: has anyone noticed there is no UIInterfaceOrientationMaskPortraitAll
mask? Seems missing to me.

Basil Bourque
- 303,325
- 100
- 852
- 1,154

rich.e
- 3,660
- 4
- 28
- 44
-
1Using the bitwise OR operator ought to cover the 'PortraitAll' use case: return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown) – jankins Nov 16 '12 at 22:46
-
Yes that works, be there is a UIInterfaceOrientationMaskLandscape, so I would hope there would be an equal version for portrait (has to of course be named something else.. which is why I appended *All).. just seems like an incomplete API to me. – rich.e Nov 18 '12 at 08:50
-
2@rich.e UIInterfaceOrientationMaskPortraitAll is not required since UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait) and accoding to position of UIDeviceOrientationPortrait in the enum it corresponds to index number 0. – Ilker Baltaci Dec 21 '12 at 08:25