I am currently looking on how to use size classes programatically here are some finding that can be useful for you:
The easiest way to find out is to just check on the view controllers traitCollection
po self.traitCollection
Or listen to transitions:
First use the UIContentContainer protocol
@interface ViewController : UIViewController<UIContentContainer>
Then implement willTransitionToTraitCollection:
- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator
{
}
The newCollection element has information that can be used for your purpose, here is the info returned when rotating an iPhone 6 to landscape:
<UITraitCollection: 0x7f9ad152f320; _UITraitNameUserInterfaceIdiom = Phone, _UITraitNameDisplayScale = 2.000000, _UITraitNameHorizontalSizeClass = Compact, _UITraitNameVerticalSizeClass = Compact, _UITraitNameTouchLevel = 0, _UITraitNameInteractionModel = 1>
And to portrait:
<UITraitCollection: 0x7f9ad142d770; _UITraitNameUserInterfaceIdiom = Phone, _UITraitNameDisplayScale = 2.000000, _UITraitNameHorizontalSizeClass = Compact, _UITraitNameVerticalSizeClass = Regular, _UITraitNameTouchLevel = 0, _UITraitNameInteractionModel = 1>
From there you can see it uses Compact Size Class for both horizontal and vertical in landscape, but uses Regular Size Class for Vertical when in portrait.