0

I'm trying to understand well Xcode's autolayout constraints, but I immediately encountered an error with UIScrollView constraints. I set up a UIScrollView with 4 constraints: each with value 0 to its parent. Next I set up an UIView as content holder with the same constraints of the UIScrollView, but I receive the following error:

ScrollView: Need constraints for: X position or width

ScrollView: Need constraints for: Y position or height

I already set up this constraints for the scrollview ( 0,0,0,0 to its parent).

Constraints and red line errors

Why Xcode tell me this? Thanks in advance.

Update

Fixed setting View.centerX = ScrollView.centerX and View.centerY = ScrollView.centerY. But why those constraints are necessary?

Community
  • 1
  • 1
pairon
  • 427
  • 1
  • 7
  • 18
  • Look at the error message: "X position _or width_". "Y position _or height_". As soon as you use auto layout with a content view in this way, you are responsible for telling the scroll view its `contentSize` thru the size of the content view. But you have not given your content view any size; it is missing width and height constraints, nor has it any subviews whose constraints can size the content view from the inside out. – matt Jun 10 '18 at 14:56
  • Nice reply, thank you! – pairon Jun 10 '18 at 15:40

0 Answers0