为什么在故事板中添加约束时所有元素都移动了? [英] Why all the element moved when adding a constraint in storyboard?

查看:17
本文介绍了为什么在故事板中添加约束时所有元素都移动了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好地为 tableView 的原型单元格设计了所有元素,但是每当我为元素添加新约束时,所有元素都会移动并变成如下图所示:

I design all my element nicely for a prototype cell of tableView,but whenever I add a new constraint for my element,all element just moved and become like image below:

这种情况经常发生,请问为什么会发生这种情况以及如何预防?

It happen often,may I know why is this happen and how to prevent it?

例如,在添加约束之前,它看起来像这样

For example,before adding constraint it look like this

中间的白色部分是一个堆栈视图,所以我将它设置为leading = 0trailing=0.然后我在stack viewleading=0 它与 stackview 对齐的所有元素再次移动并变成这样:

The white part in the center is a stack view,so I set it to leading = 0 and trailing=0.And then I add a constraint inside the stack view to leading=0 which it align with the stackview all element moved again and become like this:

如你所见,一切都消失了.为什么会这样??

As you can see,all thing just disappear.Why is this happen ya??

我添加的约束如下:

状态标签.领先 = 领先

Status Label.leading = leading

当我将 stackview 的间距设置为 10 时,也会发生这种情况,所有元素也消失了.

It happen also when I set the spacing of the stackview to 10,all the element also gone.

我在storyboard中出现了一个红色箭头,我建议使用Content Priority Ambiguous,但是我按照建议将优先级更改为252后,所有元素都会再次消失.

I have a red arrow appear in storyboard,I suggest the Content Priority Ambiguous,but I after change the priority as to 252 as suggested,all element just disappear again.

推荐答案

移除附加到内容视图的最底部元素的底部约束并添加所有剩余的约束 &加上 stackView 间距,然后重新添加底部约束

Remove the bottom constraint of the bottom most element attached to the content view and add all your remaining constraints & with stackView spacing , then re add the bottom constraint again

这篇关于为什么在故事板中添加约束时所有元素都移动了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆