8

I can't understand how can I solve this auto layout problem, i have this View:

enter image description here

There is an UIScrollView with the elements you see in the View, but the View gives me this warning:

scrollview has ambiguous content width

I can't understand how to solve this problem, I want the the view is for the full screen size, and I want that the width will be the screen width, how I can solve it?

Gabriel Tomitsuka
  • 1,121
  • 10
  • 24
Piero
  • 9,173
  • 18
  • 90
  • 160

6 Answers6

3

I observed its fix in XCode 7.3 and it is just 10 sec work. I made a video on it. Check here:

https://www.youtube.com/watch?v=yETZKqdaPiI

All you have to do, add a subview to UIScrollView with same width and height. Then select ViewController and press Reset to suggested constraint. Please check video for clear understanding.

Thanks

Vaibhav Saran
  • 12,848
  • 3
  • 65
  • 75
2

This is because you are not providing enough constraints so that Xcode can find Width of your scroll view. You can see on your screen there isn't any constraints that can be satisfied to find width of scroll view.

You can do it by providing leading and trailing space of Image view which contains fix width. It also can be done with any other views. But i will prefer control which contains fix Height & Width So there isn't require to set hugging priority or Compress resistance.

dk-obl
  • 751
  • 1
  • 5
  • 8
2

Put everything in a View and that View put inside a ScrollView.

Editor -> Embed in -> View

Borzh
  • 5,069
  • 2
  • 48
  • 64
2

The solutions is:

  1. You have a UIImageView at the top. You set the width of the UIImageView to be the same as the width of the root view of the UIViewController

  2. You set the leading and trailing space of the UIImageView to the UIScrollView to be both 0

  3. You set the height of the UIImageView to be the height you want the image to be. And then you set the view mode of the UIImageView to be 'Aspect fit'.

pumpum
  • 555
  • 3
  • 5
  • 18
0

I had the same problem a month ago. Add a constraint that makes the UIView inside the UIScrollView have the same size of the UIScrollView's content width. If you have multiple views inside the UIScrollView, put your UIViews inside a new UIView and make sure the new UIView has the same content width size as the UIScrollView.

Best regards,

Gabriel Tomitsuka
  • 1,121
  • 10
  • 24
  • Anything you did to resolve this issue. My content is already embeded in a UIView and this UIView is added to the UIScrollView. I get ambiguity issues for both height and width in scrollview. Any solution ? – Geekoder Jan 26 '15 at 09:59
0

I too faced this issue and the only way i got it solved was using the below strategy

  1. Add a scroll view and set its constraint to fill in the screen
  2. Add a UIview inside the scroll view lets call this view as the content view. In this contentView, set top, bottom, left and right margins to 0 (of course from the scrollView which is the superView);

This should do it now you can follow step 3 and continue with your UI

  1. Place your view inside the content view and add constraints to it accordingly.

Hope it helps

Bug Hunter Zoro
  • 1,743
  • 18
  • 21