69
votes

When using Auto Layout, I am unable to set up a simple UIScrollView in my view controller in Xcode 11 beta. I know that I must constrain the scroll view to the edges, and then set the scroll view width and height equal to the width and height of the entire view that contains the scroll view. However, I am not getting the option to set equal widths and heights when I attempt to do so.

When I do the right-click-drag from the scroll view to the entire main view, I get the following options:

  • Leading Space to Safe Area
  • Top Space to Safe Area
  • Trailing Space to Safe Area
  • Bottom Space to Safe Area
  • Center Horizontally in Safe Area
  • Center Vertically in Safe Area

In other videos, there is an "Equal Widths" and "Equal Heights" option that I don't seem to have.

Am I doing something wrong, or did Apple change the way scroll views work in Xcode 11?

9

9 Answers

181
votes

Disabling the content layout guides in the size inspector (ruler icon) in properties

Disabling the content layout guides in properties

I was having the same issue, and by disabling the option it was gone.

Hope it helps! :)

25
votes

I stacked with that problem as well. Found a good guide that helped me:

https://useyourloaf.com/blog/scroll-view-layouts-with-interface-builder/

Basically what you need is 9 constraints (assuming you want to scroll only vertically):

1-4: ScrollView to Superview (top, bottom, leading, trailing). Make sure to connect it to parent view and not to safe area.

5-8: Content view to Content Layout guide (top, bottom, leading, trailing).

  1. Content view Width equals width to Frame Layout Guide.
2
votes

I also encountered this problem (Version 11.0 beta 3 (11M362v)). I solved this problem by first setting the layout in xcode10 and then running it in xcode11. I haven't found any official instructions yet, proving that this is a problem with xcode11, but for now, I guess this is a problem with xcode11 bate.

2
votes

After spending a long time on this scrolling issue in Xcode-11. The conclusion on this issue is you have to choose the scrolling option while adding a new constraint.

You can refer to the following screenshot to resolve your issue.

enter image description here

These mentioned solutions worked for me.

2
votes

Disabling the content layout guides in properties worked for me.

1
votes

Well, I was facing this issue but I have found a solution. Problem is the Safe Area. enter image description here

  • Embed Scroll view in a UIview.
  • give Top, Bottom, Right and Left 0.
  • now give constraints of scroll view with this view.
  • Add Equal height and width of content view to this View.

parent view is automatically giving Safe Area. All you have to do is just embed your scroll view in a UIview and then give equal height and equal width of the content view to this view.

0
votes

For me, initially the Content Layout Guides is in disabled state by default in ScrollView. So I just enabled and disabled the Content Layout Guides then the error disappeared automatically.

0
votes

Xcode 11+, Swift 5.

I solved my issue, I prepared video and code

0
votes

@Vadim's answer worked with a little adjustment. Nothing else worked and I didn't want to disable 'Content layout guide'. Since apple enabled it, why disable it. So there must be something I'm missing or it's a bug.

Vadim's answer is:

I stacked with that problem as well. Found a good guide that helped me:
https://useyourloaf.com/blog/scroll-view-layouts-with-interface-builder/
Basically what you need is 9 constraints (assuming you want to scroll only vertically):

1-4: ScrollView to Superview (top, bottom, leading, trailing). Make sure to connect it to parent view and not to safe area.

5-8: Content view to Content Layout guide (top, bottom, leading, trailing)

9: Content view Width equals width to Frame Layout Guide.

All good, but it didn't work,

But then I realize that the above 6 and 8 (trailing and bottom constraints to 'Content Layout guide') constraints are a little weird. They had positive constant values instead of zero. Like the below image. (constant equals to width and height of the scroll view). I changed them to zero and now it all works.

enter image description here