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

帅比萌擦擦* 提交于 2019-12-04 15:26:47

问题


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?


回答1:


Disabling the content layout guides in properties

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

Hope it helps! :)




回答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.



回答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.




回答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.

These mentioned solutions worked for me.




回答5:


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

  • 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.




回答6:


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.



来源:https://stackoverflow.com/questions/56570660/how-to-fix-scrollable-content-size-ambiguity-in-xcode-11-ios-12-ios-13-usin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!