In my universal app I currently override supportedInterfaceOrientations
in the window's root view controller to define the orientations that are allowed. Up until now the decision was based on the device's user interface idiom:
- (NSUInteger) supportedInterfaceOrientations
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
else
return UIInterfaceOrientationMaskAll;
}
Now I would like to change this so that I can also support landscape for the iPhone 6 Plus, but NOT for other iPhones. I can image one or two solutions, but these are all rather brittle and will probably break when Apple starts to make new devices.
In an ideal world I would like to change the above method to look like the following snippet, where the decision is based on the device's user interface size class instead of the user interface idiom:
- (NSUInteger) supportedInterfaceOrientations
{
// Note the hypothetical UIDevice method "landscapeSizeClass"
if ([[UIDevice currentDevice] landscapeSizeClass] == UIUserInterfaceSizeClassCompact)
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
else
return UIInterfaceOrientationMaskAll;
}
Is there something like this magical landscapeSizeClass
method somewhere in UIKit? I have looked around a bit in various class references and guides, but didn't find anything useful. Or can someone suggest a different solution that is similarly generic and future-proof?
Note that my app creates its UI programmatically, so purely storyboard-based solutions are out. Also my app still needs to support iOS 7 so I can't just change everything to use size classes. What I can do, though, is to make runtime checks before I use simple iOS 8 APIs.