Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 10: Ambiguous Constraints Error When Adding Simple Constraints

I'm working in Xcode 10 and am getting some errors when trying to add some pretty simple constraints to my view.

I have a UICollectionViewCell that I'm adding a UIStackView to. I size the UIStackView to fill the cell and set the top, bottom, left, and right constraints to the Safe Area.

I used to be able to do this in Xcode 9 without error, however, it now gives me an error that I need to specify the X Position or Width and the Y Position or Height. Even when I let the interface builder add the missing constraints (Center X and Center Y) it gives the same error. I feel like this is a bug in Xcode 10, but if there are new iOS 12 requirements for constraints I don't know about I'd appreciate some help with them.

If I ignore the erroneous constraints and run the app the view does not show up properly.

enter image description here

enter image description here

enter image description here

UPDATE

I definitely think this is a bug. Notice in the screenshot below, even though I have subviews in the stack view, the errors do not go away. Also, when I add static padding to the top, left, bottom, and right it does not show properly in the layout, however it does layout properly when I run the app.

enter image description here

like image 420
tentmaking Avatar asked Sep 22 '18 14:09

tentmaking


People also ask

How do you add constraints in Xcode?

To create constraints select the button and click the Align icon in the auto layout menu. A popover menu will appear, check both “Horizontal in container” and “Vertically in container” options to center the button on the screen. Then click the “Add 2 Constraints” button.

How do I fix misplaced view in Xcode?

You can correct this by pressing Command + Option + = or selecting "Update Frames" in the |-•-| menu (I think it looks like a tie fighter).

What is constraint to margin in Xcode?

Basically if the layout margins are 8,8,8,8 (the default), a constraint with 0 leading space to container margin will have an x position of 8. Note that this is only available on iOS8 or later.


1 Answers

This is, indeed, a bug in Xcode 10. To resolve this issue, embed the stack view in another view, which has the same constraints as the stack view before:

view structure

like image 121
Tamás Sengel Avatar answered Oct 13 '22 16:10

Tamás Sengel