How to fix "Scrollable Content Size Ambiguity" in Xcode 11 (iOS 12, iOS 13) using Auto Layout

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?


Solution 1:

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! :)

Solution 2:

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.

Solution 3:

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.

Solution 4:

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.