Kafka
Kafka

Reputation: 127

Why do constraints prefer resizing of one stack over another, and how do you change this preference? (xCode)

I am trying to use constraints in xCode for Auto Layout purposes, but I am running into an issue. Shown here is the current layout of the app: Current Layout. I have two stacks, one on top and one on bottom. I have constrained the position of the top stack to be glued to the top, left, and right Safe Areas, and have constrained the bottom stack to be glued to the bottom, left, and right Safe Areas. I now want to constrain the top stack to be equal to some small spacing above the bottom stack, with only the Top Stack stretching if necessary, with the Bottom Stack staying totally stationary. Instead, I am getting the opposite, with the Bottom Stack rushing up to meet the Top Stack. How did xCode choose to make the Bottom Stack stretch, but not the top, and how do I fix this?

Here is a gif showing the problem I am having. Note that I had set the Bottom Stack to be Distributed at the bottom, so it doesn't initially appear to have stretched, but once I switch from bottom to fill you quickly see the issue: Constraint Problem Gif.

Thanks.

Upvotes: 1

Views: 50

Answers (1)

Wernzy
Wernzy

Reputation: 1098

The aspect of autolayout that you're looking for is both contentHuggingPriority and contentCompressionResistancePriority. These determine which views are more likely to stretch or compress.

Increase the vertical contentHuggingPriority of the lower stack to greater than that of the top stack, then the autolayout system will make the top stack stretch.

Upvotes: 1

Related Questions