Bdennis317
Bdennis317

Reputation: 57

UIScrollView's Content View is ignoring equal width constraint to main view on Xcode 6

I've added a Scroll View that contains a content view. The scrollview's constraints keep it just below my progress bar and attached to the leading, trailing, and bottom of the superview. The content view's constraints hold it to the sides of the scroll view, with one additional constraint: equal the width of the superview.

Everything looks great on the storyboard preview, but at runtime the scrollview's calculated width increases.

simulator

Basically, it seems that AutoLayout is ignoring my constraint to constrain the width of the content view, and instead just allows the content view to get as large as it wants to fit the content in.

Here are my constraints:

xcode 1

Thank you so much for helping me get over this roadblock! I've been banging my head against the wall for days.

Upvotes: 3

Views: 2122

Answers (1)

eager to learn
eager to learn

Reputation: 408

Here are some things I would try. I don't have comment privileges yet, otherwise I would ask for elaborations:

  1. Are there any outputs in the console for Xcode? Generally when Autolayout is forced to break constraints, it tells you about it in the logs.
  2. So to be clear, for the Content View, you have a constraint that sets the width equal to the ScrollView, as well as constraints to match the Leading and Trailing edges to the ScrollView?

If the constraint is not being followed then either the ScrollView is also expanding somehow, or the constraint conflicts with another constraint, and the width-matching constraint got broken somewhere along the way.

Upvotes: 5

Related Questions