>>May be have a look here: h ttp://synappse.co/blog/uiscrollview-has-ambiguous-scrollable-content-height/
This webpage indicates setting the ScrollView and UIView to have constraints all set to "0", which will not work for me. This example shows how the UIView gets larger when more and more text is added to the TextField thus pushing the UIButton (and text) out of the visual screen area, thus allowing scrolling to be initiated. I am assuming when the ScrollView constraints are all set to "0" then they are all RED for this guy as well, but he never mentions this at all
>>If you want to work on view larger that the viewController (for the content view), you can either:
- do it by hand, selecting objects in the list and setting the position and constraint without viewing it inside the viewController
- or use freeform for a while
- or create a xib for the view
This is not a problem. I simply reposition the content UIView, as required, within the viewController so I can see all objects which were previously off the screen. I can then assign constraints and positions as desired. This is not that bad as I am not dealing with ScrollViews that often. If I was constantly dealing with ScrollViews, then this technique would eventually get annoying.
For testing, I created a brand new Xcode project and did the following:
1) I added a ScrollView with the following constraints:
leading safe area = 0
trailing safe area = 0
top to safe area = 150
bottom to safe area = 150
- There are RED lines around the scrollview and a warning which states the "content size is ambiguous"
- I tried adding fixed width(375) and height(367) constraints to the ScrollView to see if the RED lines would go away (based on your comment) but they did not. I then removed these width/height constraints since they did not help and really should not be required anyway. Are you saying you were able to get the RED cosntraint lines to turn to BLUE by adding width/height constraints somehow?
- At this point, if you switch to "Landscape" mode you will see the ScrollView object does not resize itself based on the assigned constraints, which is odd. I guess then means I cannot assume the ScrollView dimensions will be properly set when my application enters Landscape mode. (Note: To resolve this issue, perhaps we need to place the ScrollView inside of a BaseUIView object, whose constraints are set as desired, and then ensure the ScrollView frame size is always equal to the BaseUIView? :>)
- In the viewDidLoad() I have the following --> myScrollView.contentSize = myUIView.frame.size
- The UIView is where I am planning on adding all of my buttons and labels which the user can scroll around and see.
- I do not want to set the UIView leading, trailing, top, bottom constraints to be 0 (like you did) since I do not want the UIView to be the same size as the ScrollView. I need the UIView dimensions to be larger than the ScrollView so scrolling will be allowed. I am going to use the Auto Layout "Vary for Traits" option to set different button/label/etc. constraints depending on whether I am in Portrait or Landscape modes so I need to be able to work with the complete UIView dimensions.
Questions:
a) Is there a way to resolve the ScrollView "content size is ambiguous" warning in interface builder to make all constraint lines turn BLUE?
b) In the code, I make sure the UIView height/width are correct and also make sure the "ScrollView.contentsize" is set appropriately. In order to set valid (BLUE) constraints on the objects (buttons, labels, etc.) located within the UIVIew, I must first set valid (BLUE) constraints for the UIView itself first. As a result, I set the following constraints for the UIView:
leading = 0
top = 0
width = 700
height = 700
I then set valid (BLUE) constraints for all buttons, labels, etc. located within the UIView.
When I run the application and attempt to scroll, I see the "scrollViewDidScroll( )" UIScrollViewDelegate function IS being called repeatedly, but no actual scrolling of the objects is occurring visually. The UIButtons located in the UIView can be clicked.
I discovered if I remove the UIView four constraints (leading, top, width and height) then scrolling now works visually, but none of the UIButtons are clickable. All weird stuff.
Any idea what is going on here?