I have a screen in my app with multiple child view controllers. On smaller screen sizes like iPhone, the view controllers are placed flush against each other. On iPad screen sizes, one of the view controllers floats on top of the other.
I want to make it so my view controller that sometimes floats only has a corner radius when it's floating. Therefore, I've looked into overriding a method like viewDidLoad
or overrideTraitCollection(forChildViewController:)
in my child view controller to set the corner radius of its view based on whether its size class is wRegular,hRegular, which is for iPads in portrait or landscape.
However, the child view controller doesn't seem to have the same size class values set as the root view controller, and traveling up the parentViewController
hierarchy doesn't seem to get me to a view controller that does have those values.
How should I access the current size class of the top of the view hierarchy from a child view controller?
edit: I've tried the existing answer using UIScreen, and it works great when my app is the only visible app. However, it results in incorrect behavior when the app is run in split screen mode-- it always returns Regular/Regular even if the app is narrow. Is there a solution that involves getting the size class for just the part of the screen my app is in?