Xcode 8 - How To Disable Auto Adjustment Of Views When Deleting a Constraint In Storyboard - xcode

Before when I delete a constraint that sits between two views, the position or size of the two views doesn't get affected(meaning they don't automatically adjust itself in the storyboard). But now it does. An example would be let's we have two UIButtons aligned horizontally. I set the height and width of one equal to the other. Then if I delete one button, the other button will change it's size in the interface builder.
Is there a way to disable the auto adjusting of sizes and position of views when their constraint changes?

Related

Interface Builder and NSTableView top constraint

I have the following UI definition:
I wanted to define the constraints for the components but whenever I try to add a constraint so that the Bordered Scroll View - Table View.top is topStackView.bottom + 20, I get a constraint conflict. There is a hidden constraint where the Bordered Scroll View - Table View.t must be
topStackView.bottom + 8.
So, my question is where is this +8 constraint coming from? I assume it must be from the NSScrollView that contains the table as all the components inside seem to have Translate Masks Into Constraints.
How can I properly use Auto Layout so achieve what I want?
I haven't done much with MacOS apps, but this may solve your issue...
Delete the Bordered Scroll View - Table View.top is topStackView.bottom + 20 that you're trying to add.
You have them embedded in a vertical stack view - mainStackView - so set the Spacing on that stack view to 20.
It may not look right in Storyboard / IB, but the result should be correct (I have two buttons at the top, but that won't make a difference):

Xcode 8.3.3 autolayout - view is disappearing runtime when setting constraints

I'm trying to make a divider, so what I do is:
1) Make a new View
2) Change the background to the color I want the divider to be
3) Control click and center it horizontally on a label on top of it
4) Compile, my view is gone.
5) Remove constraints, compile, my view is there.
6) Add left and right constraint for autosize, compile, view is gone.
It also states that the height of my view is ambiguous.
How can the view be gone by merely constraining it?
Screenshot:
Your view does not disappear. It just getting zero size.
When you remove constraints it won't iOS won't layout your view that is why it's size not changing.
And in you last case with leading/trailing constrains your view will calculate its width depending on it's superview width, but since system can't calculate height it gonna change it to zero.
Other views and like labels and images have content and with a help of defined intrinsic content size they system won't resize them to zero sizes but to their content size.
here is my output I tried in swift using Xcode and tried setting constraints as I do

Cocoa Resizing Two Stacked Tables

I have a view with two vertically stacked Table Views. When I resize the application window, the lower table view expands. This is because I didn't specify a height for it. It has a fixed distance to the bottom of the window and a fixed distance to the table view above it. If I attempt to remove the fixed height for the upper table view, the constraints editor complains. Is it possible to have both table view expand equally when I resize the application? If not, is the possible to allow the upper table view to be resized when the application is running?
I found a way to do this as long as there is some sort of control between the two tables. A label will work fine. Using constaints:
For the control in between the two tables, set the Alignment constraint to "Vertically in Container. This will perfectly center the control. You can offset it above or below center by adding a positive or negative value in the combobox next to the option.
For the top table, pin the top of the box to the top of the window or any other place that fits your design.
Set the bottom constraint to some offset from the control in step 1.
Set the bottom constraint of the bottom table to something fixed like the bottom of the window.
Set the top constraint to some offset from the control in step 1.
Be sure not to set the height of either table.
When the window moves vertically, the control in step 1 will be moved to keep it in the center plus or minus any offset you provided. The two tables will be expanded or contracted accordingly.

"Add New Constraints" checkboxes and fields are disabled

I have a project I am upgrading from Xcode 4.6.3 to Xcode 6.1.1. I opened it in Xcode 6.1.1, and opened each .xib. The format of each .xib changed as expected. I want to attempt to use auto layout. Use Auto Layout is checked and so is Use Size Classes. I changed every appropriate object from Alignment Frame to be Alignment Rectangle.
For a while I couldn’t add any constraints. Then after some trying I could add a few. See the screenshot.
For the selected View, I cannot add a constraint. The Add New Constraints checkboxes and fields are disabled. Only Update Frames is available to be changed. I can’t add an alignment constraint either. Ctrl-drag a line off the view does not add a constraint either. Notice the View height of 411. If I select another object, then select the View again the height will change to be the height of the parent tab bar less. If I keep doing that the height gets smaller and smaller, then Xcode crashes. How can I add a constraint to this view?
The Tab Bar X, Y, Width, and Height are disabled. When I change the Height of the Assigned View Controller View, the Tab Bar Y changes to that value minus the Tab Bar Height of 49. When I select the View, again it’s Height is now 49 less. Select the Tab Bar, it’s Y is now 49 less. And so on. How do I set the dimensions of the Assigned View Controller View that will stick when I cannot add contraints?
I had the same issue. In my case, the view layout setting was set to Translate Mask Into Constraint. I resolved it by changing it to Automatic in Size Inspector.
Xcode 12, Xcode 13
For UI elements where adding constraints are disabled, check Layout in the Size Inspector:
If Layout is set to Autoresizing Mask change to Inferred.
or
Inferred(Constraints) - The UI element already has one or more constraints.
Inferred(Autoresizing Mask) - The UI element currently has no constraints.
Steps to enable autolayouts:
Select any UI element, in storyboard.
Click on Show the Size Inspector.
Click on dropdown beside Layout option, select Automatic from dropdown.
Zev has the answer. You can't add constraints directly to the top-level view in a view controller.
In regards to the height of the View decreasing when selecting it, I started over from the original .xib making small changes and taking notes. When I checked "Use Auto Layout" and "User Size Classes", got alert the document will no longer be compatible with Xcode 5. Window frame size went from 320 568 to 600 600. ibExternalTranslatesAutoresizingMaskIntoConstraints went from 1 to 0. Other changes apparent as well. Adding constraints to objects contained in View one at a time I am getting good results. The behavior of the View height decreasing when I select it is gone.
Trick to enable constraints on the root view:
Inside the xib, drag a new view that will be sibling to the initial root
view.
Move the initial root view inside the sibling view. It will be
able to have own constraints.
Move the initial view back to be a
root.
Delete the empty sibling view.
Xcode 12 Swift 5
Select the UI Control and click on Show Size Inspector window
Change Layout option to Inferred (Autoresizing Mask))
By default the Xcode 12 keep the setting of layout to Autoresizing Mask, If you want to apply the constraint used Inferred

NSSplitView with Autolayout, prevent proportional resize

I'am using autolayout with NSSpliView, the setup is as following on the picture
The split view is in a window which can resize, when it resizes, the divider is changing proportional 50:50, how to change this, so that the height of the bottom view stays and the top view gets resized (but no more than 124px) but still have the freedom also to change it manually by dragging the split?
So just to recap you have three requirements,
Bottom view stays the same size on resize
Reduce the holding priority if the top view (select the NSSplitView to get the correct inspector)
Top view cannot resize more than 124px
Add a inequality constraint which sets the height of the view to less than or equal to 124px. You can do this in IB. It will also be a good idea to create a IBOutlet for this constraint in your custom view of controller class for the next step...
When the divider is moved the top view should be able to get smaller than 124px.
I not entirely sure but checkout the NSSplitView delegate method such as splitView:resizeSubviewsWithOldSize: or splitViewDidResizeSubviews:. When you resize with the divider the delegate method should override the height constraint to be the current resized size. So something like the following in the delegate method
self.heightConstant.constant = NSHeight(topView)
Or you could just remove the constraint and re-add it later when needed.

Resources