Xcode 11 添加新的约束设置为零:使用设置值而不是默认值/标准

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/59425096/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:03:46  来源:igfitidea点击:

Xcode 11 add new constraints set zero: use set value instead of default / standard

xcodeautolayoutinterface-builderxcode11xcode11.3

提问by Eddie

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

我曾经使用自动布局添加新的约束来对超级视图/相对视图进行简单的约束,就像这样(对于 loooong 时间):

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:

但是,最近更新到最新的 xcode(11.3.3 或 11.3/11C29)后,我遇到了这个奇怪的问题:当我设置常量 = 0 时,它们总是以不需要的方式生成约束,如下所示:

enter image description here

在此处输入图片说明

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

似乎默认值在某种程度上是 20 并且让我的观点看起来如此错误(0 与 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)

然后它会再次更正(图像是在编辑约束之后,在编辑之前显示常量 = Standard

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

我什至不知道如何描述这个问题,但我如何解决这个新问题add new constraint以使用我的愿望点而不是标准/默认值?

Update:

更新:

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

它似乎只发生在约束超级视图时。不知道如何修复tho。

Update Apr-01-2020:

2020 年 4 月 1 日更新:

Xcode11.4 fixed this.

Xcode11.4 修复了这个问题。

采纳答案by matt

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

似乎是一个错误(不要忘记向 Apple 提交文件)。这是一个简单的解决方法:

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.01is not the same as 0but 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.

当您在“弹出窗口”中填写数字时,不要输入0,而是输入0.01。这将防止数字神秘地更改为“标准”。好吧,所以0.01不一样,0但它足够接近,你无法分辨出区别,至少你以后不必回去更改它。

EDITApple says that this bug will be fixed in Xcode 11.4:

编辑Apple 表示此错误将在 Xcode 11.4 中修复:

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

修复了阻止在约束弹出编辑器中输入 0 常量的错误。(54076090)

回答by chhay sotheara

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

当@matt 解决方法有效时,我只想补充一点,您可以将其设置为 0.01,然后将其更改为 0,它不会再次更改为标准值。注意:Xcode 11.3

回答by Dave Y

As of Xcode 11.3.1:

从 Xcode 11.3.1 开始:

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

我发现的最简洁最快的解决方案如下:

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

只需在-0约束字段中输入即可。Xcode 似乎丢弃了负数并且它的行为正确,这比它读取0.01所有内容都要好。

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

Xcode 显示的值是这样的

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.

编辑:这似乎并非每次都有效,这令人沮丧。我刚刚有一个 UIImageView 向 Superview 显示 0,但在视觉上仍然处于默认值 (20)。这确实看起来像是 IB 的一个错误,因为这种行为完全不合逻辑。

Edit 2: Seems to be fixed now - phew!

编辑 2:现在似乎已修复 - 呸!

回答by dequin

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

此行为似乎已在 Xcode 11.4 上修复:发行说明

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

修复了阻止在约束弹出编辑器中输入 0 常量的错误。(54076090)



Original Answer:

原答案:

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

我也刚刚发现了这种行为,我尝试按 1 添加约束,而 Xcode 实际上尊重 0 值。

My two cents.

我的两分钱。

回答by Gon?alo Gaspar

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.

我知道这不是解决方案,但是对于防止您通过每个约束的临时解决方案,我刚刚发现如果您插入“-0”而不是“0”,您将获得所需的行为,但您必须插入一个每次都约束。

回答by Ahmed Samir

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 .

但最好的临时解决方案是一一添加零约束。

回答by Jirakit Paitoonnaramit

ignore that when standard.

当标准时忽略它。

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

添加后单击约束(蓝线)和检查器以约束属性并将其设置为 0。

that work for me

这对我有用

回答by Jaskirat Singh

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.

仍然遇到这个错误(Xcode 11.3.1)。通过简单地将约束添加为“标准”,然后单击蓝色约束线并将大小检查器下的“常量”设置为 0 来修复它。