objective-c “图像视图”的位置和大小不明确

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

Position and size are ambiguous for "Image view"

iphoneobjective-cautolayoutuistoryboard

提问by yong ho

I am trying to set a UIImageView has no fixed size and width in the storyboard. I set the leading space to container to greater than or equal to 20, top space to the container to greater than or equal to 20 and trailing space to container to greater than or equal to 20 and vertical spacing to a UICollectionView, the UICollectionView satisfy the constraints. But the UIImageView don't work, it's telling me it's Position and size are ambiguous. How can I make it work? My Idea is no matter how large the image view, it will always keep 20 space to leading, top, trailing and bottom.

我正在尝试设置一个 UIImageView 在故事板中没有固定的大小和宽度。我设置容器的前导空间大于等于20,容器顶部空间大于等于20,容器尾部空间大于等于20,垂直间距设置为UICollectionView,UICollectionView满足约束。但是 UIImageView 不起作用,它告诉我它的位置和大小不明确。我怎样才能让它工作?我的想法是无论图像视图有多大,它都会始终保持前导、顶部、尾部和底部的 20 个空间。

I have set the height and width to be greater than or equal to some value and their priority to 999, it's lower than the leading, top and trailing priority. and I have set the imageview to center horizontally. but i get height and vertical position are ambiguous for “Image view”.

我已经将高度和宽度设置为大于或等于某个值,并且它们的优先级为 999,它低于前导、顶部和尾随的优先级。我已经将图像视图设置为水平居中。但我得到“图像视图”的高度和垂直位置不明确。

回答by Arek Holko

Can you see what happens when you add height and width constraints to the UIImageView, but set their priorities to some low value, e.g. 1? It should help, but now UIImageViewwon't be centered. You can fix it by enclosing UIImageViewin another view (empty UIView) and centering it in it both horizontally and vertically.

您能看到当您向 中添加高度和宽度约束UIImageView但将它们的优先级设置为某个低值(例如 1)时会发生什么吗?它应该会有所帮助,但现在UIImageView不会居中。您可以通过将其封闭UIImageView在另一个视图(空UIView)中并将其水平和垂直居中来修复它。

回答by Sumoanand

When you get this error:

当您收到此错误时:

Position and size are ambiguous for “view”

“视图”的位置和大小不明确

Probably following constraints are missing/incorrectly set:

可能缺少/错误地设置了以下约束:

  1. Width constraint (size issue)
  2. Height constraint (size issue)
  3. Alignment constraints (position issue)
  1. 宽度限制(尺寸问题)
  2. 高度限制(尺寸问题)
  3. 对齐约束(位置问题)

回答by Prahas David Nafissian

If you are using Stack Views, make sure the Photo Image View is inside the Stack View! (As in the Apple Tutorial)

如果您使用堆栈视图,请确保照片图像视图位于堆栈视图内!(如 Apple 教程中所述)

回答by moger777

In cases where the height/width are not ambiguous at runtime, but ambiguous at storyboard time, e.g., setting an image dynamically, having a container view, etc, I try to add constraints with the placeholder checkmark checked to silence xcode.

如果高度/宽度在运行时不模糊,但在情节提要时不明确,例如动态设置图像,具有容器视图等,我尝试添加约束,检查占位符复选标记以使 xcode 静音。

回答by Indra

If you want to give margin kind of thing into button through coding than please try these if it'll work

如果您想通过编码将边距类型的东西添加到按钮中,请尝试这些是否可行

[button_Name setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 12.0, 0.0, 0.0)];

I hope this will work..!!!

我希望这会奏效..!!!