This my another solution using priority constraint. The idea is set the width to 0.
create container view (orange) and set width.

create content view (red) and set trailing space 10pt to superview (orange). Notice trailing space constraints, there are 2 trailing constraint with different priority. Low(=10) and High(<=10). This is important to avoid ambiguity.

Set orange view's width to 0 to hide the view.
