How to fix scrollable content size ambiguity in xcode 11 using auto layout beta 7 UIKIT - xcode

When using Auto Layout, I am unable to set up a simple UIScrollView in my view controller in Xcode 11 beta 7. 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?
I'm using beta 7 currently

I was finally able to successfully add a UIScrollView using storyboards in Xcode Version 11.0 (11A420a) after much trial and error.
You can add the scroll view directly to the root UIView of the VC or, if you needed to, add it to another UIView under the root view as needed by your UI Design. Constrain the UIScrollView parents normally for whatever your needs are.
Here is the key : when you add the UIScrollView to the storyboard, click on the Size Inspector with the UIScrollView selected. You have to UNCHECK the box that says "Content Layout Guides".
If you do this you can set the scroll view's contraints normally (I did 0-0-0-0 to superview). Then I added a UIView to the scrollview and set it's constraints to 0-0-0-0 and a height of 900 (which is what I wanted).
This will give you constraint errors in red when you set them. They will be fixed by setting the width of the UIView equal to the width of the UIScrollView.
Set the UIView width equal to the width of the UIScrollView view by Ctrl-right clicking on the UIView, dragging to the UIScrollView, and selecting the "Equal Widths" option. This should get rid of your constraint errors.
You actually can then go back to the UISCrollView Size Inspector and check the "Content Layout Guides" checkbox, no constraint errors will appear.

Disable the content layout guides in scrollview properties.
Hope it helps.. :)

Related

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?
Disabling the content layout guides in the size inspector (ruler icon) in properties
I was having the same issue, and by disabling the option it was gone.
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).
Content view Width equals width to Frame Layout Guide.
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.
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.
Disabling the content layout guides in properties worked for me.
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.
#Vadim's answer worked with a little adjustment.
Nothing else worked and I didn't want to disable 'Content layout guide'. Since apple enabled it, why disable it. So there must be something I'm missing or it's a bug.
Vadim's answer is:
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)
9: Content view Width equals width to Frame Layout Guide.
All good, but it didn't work,
But then I realize that the above 6 and 8 (trailing and bottom constraints to 'Content Layout guide') constraints are a little weird. They had positive constant values instead of zero. Like the below image. (constant equals to width and height of the scroll view). I changed them to zero and now it all works.
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.
Xcode 11+, Swift 5.
I solved my issue, I prepared video and code

UIScrollView contentInset is set to nonZero when using autolayout

So I have the following view hierarchy :
A full size scrollView in my viewController's view with the following constraints :
These are the constraints on containerView (ignore the second last one, its a hacky semi-fix for my problem):
I have the status bar, the navigation bar and the tab bar visible.
The thing is that when I set a breakpoint to check the scrollView's contentInset, it shows 64 on top and 49 on bottom, left and right are zero.
There is no way to set contentInset in IB, I tried setting it in an IBAction to UIEdgeInsetZeio, but that didn't fix it either. This is screwing up my scrollview by adding space above and below my contentView, how can I fix this?
By default the view controller extends the view under the top navigation bar so your content will blur under a translucent navigation bar. This is controlled by edgesForExtendLayout which is managed in Storyboard via the Extend Edges setting.
By default, the scrollview will automatically adjust its content inset so the content appears below the top layout guide. This is controlled by automaticallyAdjustsScrollViewInsets which is also managed in Storyboard.
What you did was constrain the top of your scroll view to the top layout guide instead of the top of its superview. By doing this, you manually offset it by 64 points. However, the scrollview is still automatically insetting its content by 64 points, which is why you're seeing additional space above and below your scroll view.
Either constrain your scrollview to its superview (so its content scrolls under the top/bottom bars), or disable the view controller from automatically adjusting the scroll view inset.

Overflow-Y scroll not working

I got the constraints just how I want it in iPhone 5 it fits in one screen and in iPhone 4 it overflows to the bottom which is fine. But why can't I scroll down?
iPhone 5:
iPhone 4:
As you can see in iPhone 4 the bottom is not visible and all I want is to be able to scroll there.
Even without seeing how you are settings the constraints on the Interface Builder, I think that doing like below could help you to solve your problems:
Possibly you are not embeding all views in a scrollView properly. If so, select all subviews, choose Editor from menu -> Embed In -> View to wrap everything in a container. (UIView). After that select the container then choose Editor -> Embed in -> Scroll view
Set up all necessary constraints between subviews and the container ( As you did before making the view in the shared screenshot)
Set up all margins between the container and the containing scrollView to be zero ( top/ left/ right/ bottom = 0). Ensure that the scrollView fit the screen by having zero margin constraints as well.
Last but not least, set a width constraint of the container to any number you want (e.g.: 320 /375), then make an IBOutlet for this constraint
On viewDidLoad, set the constant of the container's width constraint you made in step 4 to current screen width.
That's all.

UIScrollview scroll not working

UIScrollview scroll is not working when i tested application in device (iPhone 5), But scroll is working properly in iPhone 5/5s/6/6 Plus simulator. I am developing application using Xcode 6 and UIStoryboard with AutoLayout.
I set the top, bottom, left and right constraints of UIScrollview with relative to Superview. And i also set the constraints of every UIControl which is in the UIScrollview.
Has any one have solution regarding this issue?
Please see below screenshot for reference.
It's probably easiest to have the scroll view contain a single view, which then contains all of your scrollable content. That single view should be anchored to all 4 sides of the scroll view, and if it's only meant to scroll vertically (which is what your screenshot makes it look like), then set the content view to be the same width as the parent of the scroll view.
To make sure an UIScrollView scroll, you have to check
Size
Your content View is bigger than your Scroll View. If you want it to be scrolled vertically, make sure its higher; horizontally, wider.
Constraints
Make sure your Scroll View is pinned to its super view, Top, Bottom, Leading, Trailing.
Make sure your Content view of Scroll View DOES NOT have CenterY constraint set to Scroll View, cause that'd make content view stuck with Scroll View and it'd never be able to scroll. (That happens to me the last time I was stuck)
Interface Builder settings
Make sure the check in Interface Builder under Scroll View is checked:
Scrolling section, Scrolling Enabled.

Xcode Storyboard New Item Full Width and Height

When I drag an object to a view in the Xcode Storyboard, it assumes the full width and height of the containing view, rather than the default dimensions. For instance, I drag a UIButton to an iPad View, and suddenly it's 1024x768 pixels, and for some reason, the width and height properties are grayed out in the configuration window with the ruler on the right. Any ideas why that is and how to fix it?
Per our comments above, just add a view to the view controller first, then add the button.

Resources