As a confirmation, this is the current behavior:

And this is what you ask for:

To achieve this, you can take advantage of this simple trick:
PS: I assume that you have added the necessary restrictions for your stack view.
If your stack view has no height limit, add it:

Now add it as an IBOutlet to the designated ViewController; In my example, I call it stackHeight :
@IBOutlet weak var stackHeight: NSLayoutConstraint!
In case you want to hide the view (in my example, I hide the orange button based on the IBAction assigned to it, when I touch it, it should be hidden), you need to get the height of the view that you want to hide and subtract from stackHeight.constant :
@IBAction func orangeTapped(_ sender: AnyObject) { orange.isHidden = true
Ahmad f
source share