In my generic application, I am currently redefining supportedInterfaceOrientations in the window's root window controller to determine the allowed orientations. So far, the solution has been based on the idiom of the device user interface:
- (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 the landscape for the iPhone 6 Plus, but NOT for other iPhones. I can create one or two solutions, but all of them are quite fragile and are likely to break when Apple starts creating new devices.
In an ideal world, I would like to modify the above method to look like the following snippet, in which the solution is based on the device user interface size class, and not on 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 magic landscapeSizeClass method somewhere in UIKit? I looked around a bit in various reference books and class manuals, but did not find anything useful. Or can someone suggest another solution that will be similarly universal and promising?
Please note that my application creates a programmatic interface, so there is no reason for a storyboard based solution. Also, my application still needs iOS 7 support, so I can't just change everything to use size classes. However, I can do performance checks before using the simple iOS 8 APIs.
source share