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

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

Related

What is the name of this macOS UI Control? [duplicate]

I think I must be missing something simple but being new to Xcode... Specifically I am coding in Swift but I believe this is more of a .xib file question. It is easy to have add and delete buttons outside of an NSTableView (like the native Mail app's Preferences->Signatures panel) but how do you integrate these into what seems to be the NSTableView itself? (more like the native Mail app's Preferences->Accounts panel) Ideally I want the option to have more than just add / delete buttons present but once I understand the process adding more functionality should be easy.
These buttons are not integrated, it's just an NSSegmentedControl aligned to the bottom of the table view.
To get this particular appearance of the NSSegmentedControl
Set Style to Small Square
Set Mode to Momentary
Set the Image of Segment 0 to NSAddTemplate
Set the Image of Segment 1 to NSRemoveTemplate
Set the width of Segment 0 and 1 to Auto
Set the width of Segment 2 to a fixed width.
The particular example you showed is just some buttons in a container view abutting the bottom of the scroll view that contains the table view. The container view draws a background to match the buttons and a border. It's probably actually "underlapping" the scroll view by a point so you don't get a doubled border between them.
In fact, if you look carefully, the container view is one point too narrow, so that its right border doesn't match the right border of the scroll view. That kind of proves that it's not part of or in the scroll view.
I also had the same question & I posted an answer here :)
But what I think is its a NSView containing 2 NSButtons for + & - as posted in my answer linked above.

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

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

Why isn't storyboard safe area working correctly on iPhone X?

I'm trying to update my app for the new iPhone X. After reading about the safe area feature and the check box "Safe Area Relative Margins" in each UIObject's "Size Inspector" (ruler tab), I didn't think this would be too bad. However, that feature does not seem to be working for me.
Nothing changed for regular iPhones, which is good, however for the X, the top of my app overlaps the top inset of the phone by a third. Is there any known way to fix this* or something I'm missing?
*By fix this, I mean make it so that my objects start below the outcrop, like the second picture.
What is happening:
Desired Behavior (from https://arstechnica.com/gadgets/2017/11/how-devs-updated-their-apps-for-the-iphone-xs-screen-and-the-notch/):
I too have wasted hours on this. And while I cannot answer your question of why this is broken in Xcode, I can provide a solution.
But first let me note than in Xcode 11.3.1, I experience the same issue in a new project created from scratch.
Set up your storyboard:
On your storyboard, select "Use Safe Area Layout Guides". This will add a safe area to each of your ViewControllers. It will also require you to target iOS9+. You might be able to skip this step though (see step 4 below).
View your storyboard as iPhone 4s.
Fix each ViewController:
Select all views under the top-level view.
Click Editor | Embed In | View Without Inset. This creates a new view and puts all your views inside.
Make this new view expand to the safe area by adding safe area constraints (by control-dragging your new view onto the top level view).
Leading space to safe area
Top space to safe area
Trailing space to safe area
Bottom space to safe area
If you did not opt into using a safe area storyboard above, you may be able to create four equivalent constraints by using the Top Layout Guide, Bottom Layout Guide, and the left/right sides of the top-level view. This may not work in landscape though. And I did not test this.
Set your new view as transparent.
Give your new view a name like "SafeAreaView".
In iOS 11, margins are inset from the safe area. Thus, your zero top margin becomes a 20 top margin — explaining your screen shot. If that's not what you want, set the view's insetsLayoutMarginsFromSafeArea property to false.
In my case modalPresentationStyle = .fullScreen has to be set to the view controller being presented

ScrollView margins

I've been working with Xcode and Swift 3 for a couple of weeks and I keep encountering the same issue. When I have a UIScrollView with elements inside I always get a margin around the entire scroll view of about 20, this is even though all my constraints are set to 0 - so its pinned to all sides. I have copied code from various tutorials and read numerous StackOverflow posts but I just can't seem to sort this issue out.
My page is set out like this:
Scroll View (contraints: Align Centre X, trailing/leading/bottom/top spaces to the superview
Stack View (Child of the scroll, all constraints the same as above)
When I rotate the page it adjusts the size of everything perfectly using the auto layout stuff, but the margin is still there.
I have tried to manually adjust the size of the scroll view but whenever I run the app it makes no difference.
I am absolutely baffled how I can sort this issue.
A screenshot of my scrollview, more can be added if needed.
Double click on a constraint and it will open up the detailed view which shows the first item, relation and second item.
Click on "Superview.Trailing Margin" and untick "Relative to Margin"

Adding Constraint to a ScrollView

I have a scrollView that I have stretched the full width of the iOS application in Xcode. I'm using Xcode 6 and size classes so the width is set to 600X600 in the view panel. when I go to add a the constraints in IB, it shows 0 for the top, -16 for the left and right and 0 for the bottom. My question is why does it show -16? It appears as though all sides should display 0. I'm just trying to get a better understanding on how constraints work when using the new size classes.
Did you note the "Constraint to margins" checkbox? Thats what playing tricks with you I think.

Resources