Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 657
Pranav Ramesh Avatar asked Jun 12 '19 21:06

Pranav Ramesh


People also ask

What is scroll view in IOS?

Overview. UIScrollView is the superclass of several UIKit classes, including UITableView and UITextView . A scroll view is a view with an origin that's adjustable over the content view. It clips the content to its frame, which generally (but not necessarily) coincides with that of the app's main window.


3 Answers

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

like image 68
Juan David Torres Avatar answered Oct 19 '22 21:10

Juan David Torres


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.
like image 44
Vadim Avatar answered Oct 19 '22 20:10

Vadim


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.

like image 2
zheng Avatar answered Oct 19 '22 22:10

zheng