When I rotate my view controller on an iPad 8.4, my view doesn't extend all the way to the right:
In this example, the red view is my root view controller, and it should never be visible. I embed a navigation controller using UIViewController containment, and that should fill up the entire screen and cover the red portion.
Why is it causing this behavior, and how can I resolve it?
If I try running it on an iPhone, or iOS 9, it is fixed.
I was able to reproduce the problem with a minimum amount of steps:
Steps to reproduce problem (or try this GitHub project):
Things that fix it:
autoresizingMask
from<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
to<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
. (By default when you drag in a view controller to the storyboard, it will use the...Sizable
variants. If, however, you delete the view (not the view controller), then drag a view back into the view controller, it will use theflexibleMax...
variants.)translatesAutoresizingMaskIntoConstraints
is set toYES
rather thanNO
. If you compare the auto layout way of embedding a view controller vs. the storyboard way of embedding a view controller, you will see that the storyboard setstranslatesAutoresizingMaskIntoConstraints=YES
, therefore, instead of trying to set up constraints, simply keep translatesAutoresizingMaskIntoConstraints set to YES, and set thechildView.frame = parentView.bounds
, to mimic the storyboard embedding behavior. (Note, you can also see that by default the storyboard will have the embedded view'sautoresize
set toW+H
, so you should ensure that your view has that set.)