Uiscrollview Scrollable Content Size Ambiguity

UIScrollView Scrollable Content Size Ambiguity

Updated

Nowadays, Apple realized the problem we solved many years ago (lol_face) and provides Content Layout Guide and Frame Layout Guide as part of the UIScrollView. Therefore you need to go through the following steps:

  1. Same as above;

  2. For this contentView, set top, bottom, left, and right margins to 0 pinning them to the Content Layout Guide of the scroll view;

  3. Now set the contentView's height equal to the Frame Layout Guide's height. Do the same for the width;

  4. Finally, set the priority of the equal height constraints to 250 (if you need the view to scroll vertically, the width to scroll horizzontally).

Finished.

Now you can add all your views in that contentView, and the contentSize of the scrollView will be automatically resized according with the contentView.

Don't forget to set the constraint from the bottom of the last object in your contentView to the contentView's margin.

Original [Deprecated]

So I just sorted out in this way:
  1. Inside the UIScrollView add a UIView (we can call that contentView);

  2. In this contentView, set top, bottom, left and right margins to 0 (of course from the scrollView which is the superView); Set also align center horizontally and vertically;

Scrollable content size is ambiguous to ScrollView

Here is the trick that worked for me:

  1. Add a ScrollView to your wished ViewController.

  2. Select it in the Outline and open its size inspector.

  3. Uncheck there the option "Content Layout Guides".

  4. Now set leading/top/trailing and bottom constrains to 0 of the ScrollView.

  5. Add in a UIView and constrain its leading/top/trailing and bottom also to 0.

  6. Add an equal width constrain to the UIView. (The width needs to be equal the width of the view from the ViewController, with this way you are disabeling horizontal scrolling).

  7. The warning will disappear if every element inside the UIView is chained vertically. This means, that the top element has a constrain to the top of the view and to the element under it and so on. The last element needs a constrain to the bottom of the view.

If you followed this steps you should be fine with ScrollViews. This way you also can add as many content as you want to the bottom and the ScrollView will extend dynamically.

I hope I explained it well enough.

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

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

scrollview has ambiguous scrollable content height & Width

Scroll views are special when you set constraints. Because they have an undefined content size you must set constraints for both its contents' sizes and edges. Setting only top, bottom, left, right is not enough, also set height and width.

Try this. Add a single UIView to an otherwise empty scroll view. Then tie the edges of the view to the scroll view. Finally set the height and width to fixed size.

Read more

ScrollView has ambiguous scrollable content height

You need to ensure you've got a chain of vertical spacing constraints from the top of the scroll view through all your elements to the bottom of the scroll view.

Once you do that, your warning/error should go away.

UIScrollView has ambiguous scrollable content but it has no content

Presumably, you are laying this out with the intention of adding subviews (with proper constraints) to the scroll view at run-time.

But, Storyboard / Interface Builder has no idea what your code is going to do in the future.

You can either leave it as is and ignore the warning,

or

Tell Storyboard to stop warning you about it by selecting the scroll view and then selecting Ambiguity: Never Verify in the size inspector pane:

Sample Image

or

Add some content, such as a UIView that you will use to hold the UI elements you plan to add at run-time.



Related Topics



Leave a reply



Submit