xcode 宽度和水平位置不明确

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35289858/
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 08:31:01  来源:igfitidea点击:

Width and Horizontal Position Are Ambiguous

xcodeswiftconstraintsambiguous

提问by Glyphs

it seems I have created a simple Image view with the following constraints:

似乎我创建了一个具有以下约束的简单图像视图:

Align Center X to: Superview

将中心 X 对齐到:超级视图

Align Center Y to: Superview

将 Y 中心对齐到:超级视图

Top Space to: Top Layout Guide

顶部空间:顶部布局指南

Bottom Space to: Bottom Layout Guide

底部空间到:底部布局指南

And I have the Width and Horizontal Position Are Ambiguousmessage. I am trying to correct it, but I am not sure about what is happening in the first place.

我有Width 和 Horizo​​ntal Position Are Ambiguous消息。我正在尝试纠正它,但我不确定首先发生了什么。

Do you have an idea?

你有想法吗?

回答by konrad.bajtyngier

You need to add the same constraint for left and right as you did for top and bottom.

您需要为左侧和右侧添加与顶部和底部相同的约束。

Or set fixed width.

或者设置固定宽度。

回答by rushisangani

Remove Top Space to: Top Layout Guideand Bottom Space to: Bottom Layout Guideconstraints, Set Image's Width and Heightinstead or (Width + Aspect ratio). Because every view needs x,y, height, width to render itself.

移除Top Space to: Top Layout GuideBottom Space to: Bottom Layout Guide约束,改为设置图像的宽度和高度(Width + Aspect ratio)。因为每个视图都需要 x,y, height, width 来渲染自己。

So You've already set X and Y using Align Center X to: Superviewand Align Center Y to: Superview. So it needs specific width and height now.

所以你用已设置的X和Y居中X到:上海华居中y以:上海华。所以它现在需要特定的宽度和高度。

回答by Devanshu Saini

As you have told for constrainst: Align Center X to: Superview

正如您所说的约束:将中心 X 对齐到:超级视图

Align Center Y to: Superview

将 Y 中心对齐到:超级视图

Top Space to: Top Layout Guide

顶部空间:顶部布局指南

Bottom Space to: Bottom Layout Guide

底部空间到:底部布局指南

The left option is of width Consider that any view which is placed behaves like expanding to and fro, we have to stablise it by putting constraints, your missing constraints for setting width (either from leading and trailing or from width) is making this issue

左边的选项是宽度考虑到放置的任何视图的行为都像来回扩展,我们必须通过放置约束来稳定它,设置宽度(从前导和尾随或从宽度)缺少的约束正在导致这个问题

回答by sundersparks

Go to Editor > Resolve Autolayout issue > Add Missing Constraint

Editor > Resolve Autolayout issue > Add Missing Constraint

Then the get the solution on the error page, what needs to be updated for example refer to the image where the heightneeds to be modified to 21from 20

然后在错误页面获取解决方案,需要更新的地方例如参考height需要修改为21的图片20

enter image description here

在此处输入图片说明