77

I used to use autolayout add new constraints to make simple constraints to superview / relative view like this (for loooong time):

enter image description here

However, recently after updated to the latest xcode (11.3.3 or just 11.3/11C29), I have this weird issue: when I set the constant = 0, they always generate the constraints in an unwanted way like this:

enter image description here

And it seems default value is somehow 20 and making my view look so wrong (0 compared to 20?)

If I fix that by edit the constraint like this:

enter image description here

Then it'll correct again (the image is after edited the constraints, before edited it display constant = Standard)

I don't even know how to describe the issue, but how do I fix this new add new constraint to use my desire point instead of standard / default?

Update:

It seems to only happened when constraint to superview. No clue how to fix tho.

Update Apr-01-2020:

Xcode11.4 fixed this.

Eddie
  • 1,903
  • 2
  • 21
  • 46
  • 2
    Same problem here. I think this appeared for the first time when I did update to the 11.3 UPD: Same project doesn't have this issue on another machine with the same version of xcode. Maybe it is related to the IDE config or maybe it's a bug of IDE itself. – Dmitrij Rogov Dec 20 '19 at 14:30
  • 1
    Same issue here. Using Xcode 11.3 (11C29). – user525504 Dec 20 '19 at 20:07
  • 1
    Same issue Version 11.3 (11C29) – user832 Dec 22 '19 at 05:27
  • 1
    @DmitrijRogov I recalled sometimes before (xcode 8,9 or 10), there's a setting somewhere that helps us define the `standard` value (so we can set 10 or 0 instead of `default = 8`) but I forgot where it is now. Or maybe they removed the feature? – Eddie Dec 23 '19 at 06:44
  • 6
    This is driving me crazy – Buyin Brian Dec 23 '19 at 18:27
  • They **really** want us to use margins... – Lord Zsolt Feb 05 '20 at 15:08

8 Answers8

41

Seems like a bug (don't forget to file with Apple). Here's a simple workaround:

When you fill in the number in the "popover", instead of typing 0, type 0.01. This will prevent the number from changing mysteriously to "Standard". Okay, so 0.01 is not the same as 0 but it's close enough that you can't tell the difference, and at least you don't have to go back and change it later.

EDIT Apple says that this bug will be fixed in Xcode 11.4:

Fixed a bug that prevented entering a 0 constant in the constraint popup editors. (54076090)

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • But setting it to 0 the second time works. Why bother with 0.01? It's quite annoying anyway. Good thing it's a bug and not a "feature". – Vlad Rusu Feb 27 '20 at 12:19
12

While @matt workaround is working, I just want to add on that you can set it to 0.01 and then change it to 0, it won't change to the standard value again. Note: Xcode 11.3

chhay sotheara
  • 349
  • 2
  • 4
11

As of Xcode 11.3.1:

The neatest and fastest solution I've found is as follows:

Simply type in -0 into the constraint field. Xcode appears to discard the negative and it behaves correctly, which is better than it reading 0.01 for everything.

You can insert all constraints at once, without having to do one at a time or go and edit later.

Xcode displays the values as this

It does seem like really dumb behaviour. Is there a reason that Apple might have made it do this deliberately...?

Edit: This doesn't seem to work every time, which is frustrating. I've just had a UIImageView show 0 to Superview, yet still visually be at the default value (20). This really does seem like a bug with the IB as the behaviour is totally illogical.

Edit 2: Seems to be fixed now - phew!

Dave Y
  • 414
  • 4
  • 7
9

This behavior seems to be fixed on Xcode 11.4: release notes

Fixed a bug that prevented entering a 0 constant in the constraint popup editors. (54076090)


Original Answer:

I just found this behavior too, I tried adding the constraints 1 by 1 and Xcode actually respected the 0 value.

My two cents.

dequin
  • 906
  • 12
  • 19
5

I know that this is no solution, but for temporary solution to prevent you to go through every constraint, I just found out that you get the desired behaviour if you insert '-0' instead of '0', but you have to insert one constraint each time.

Gonçalo Gaspar
  • 272
  • 1
  • 9
  • this is actually a good option, adding a '-0' when you create the constraints will be '0' in the inspector, no need to go there and change them – busta117 Jan 24 '20 at 01:21
1

There's actually no way to solve this issue at the mean time

but the best temporary solution is to add the constraints with zero one by one .

Ahmed Samir
  • 291
  • 3
  • 6
0

ignore that when standard.

after add it click on constrain (blue line) and inspector to constrain attribute and set it to 0.

that work for me

0

Still experiencing this bug (Xcode 11.3.1). Fixed it by simply adding the constraints as "standard", then clicking on the blue constraint lines and setting the "constant" under size inspector to 0.