[英]Image is not working as expected with constraints
I have a root UIView
(for rendering shadow) and it's content is another UIVIew
that contains a UIImage
and some labels at the bottom. 我有一个根UIView
(用于渲染阴影),它的内容是另一个UIVIew
,它在底部包含一个UIImage
和一些标签。 When I look at a sample poster with my constraints set up in interface builder, it looks more or less how I want it. 当我查看在接口生成器中设置了约束的示例海报时,它看起来或多或少是我想要的。
In this screenshot, the DropshadowUI View
holds the content and renders a shadow. 在此屏幕快照中, DropshadowUI View
包含内容并渲染阴影。 The CardView
holds both the UIImageView
and the UILabel
s at the bottom. CardView
在底部同时包含UIImageView
和UILabel
。 The DropshadowUI View
is transparent, the CardView
has a blue background and is the full height/width of the dropshadow (w/ a little bit of margin) and the UIImageView
has a green background to help distinguish the views while testing. DropshadowUI View
是透明的, CardView
具有蓝色背景,并且是阴影的整个高度/宽度(带有一点边距), UIImageView
具有绿色背景,有助于在测试时区分视图。 You can see that the UIImageView
takes up roughly 80% of the CardView
layout, which is desired. 您可以看到, UIImageView
大约占据了CardView
布局的80%,这是理想的。 The rest of the CardView
is made up of the UILabel
s. CardView
的其余部分由UILabel
。
When I run the app however, the constraints don't seem to be working the same way as shown in interface builder. 但是,当我运行该应用程序时,约束似乎与界面构建器中所示的工作方式不同。 The UIImageView
stretches to take the entire height of the CardView
. UIImageView
拉伸以占据CardView
的整个高度。 The UILabel
s are hidden from sight because of this. 因此, UILabel
被隐藏起来了。 Judging from the green blur behind my UINavigationBar and UITabBar, it appears that the UIImageView
is stretching vertically beyond the extents of the visible area, despite the image not even being that large. 从我的UINavigationBar和UITabBar后面的绿色模糊来看,尽管图像甚至没有那么大,但UIImageView
似乎垂直延伸到可见区域的范围之外。
The UIImageView
image is set in the interface builder for now (will be set programmatically when this is working). 现在,在界面生成器中设置了UIImageView
图像(将在工作时以编程方式设置)。 The Content Mode is Aspect Fit. 内容模式为纵横比适合。 Why does the UIImageView
stretch vertically? 为什么UIImageView
垂直拉伸? The Status
label has a Bottom Space to bottom of Superview set at 8 points. Status
标签的Superview底部到底部的空间设置为8点。 The Year
label's Bottom Space is constrained to the top of Status. Year
标签的底部空间被限制在状态的顶部。 The Movie Title
s bottom is constrained to the top of Year
. 该Movie Title
的屁股被约束到顶部Year
。 Movie Title
has it's top constrained to the bottom of the UIImageView
. Movie Title
的顶部被限制在UIImageView
的底部。 The assumption was that the labels would prevent the image view from growing on the bottom, and instead getting taller by stretching the top (which is constrained to the superview views top. 假设标签将阻止图像视图在底部生长,而是通过拉伸顶部而变高(这仅限于Superview视图的顶部。
Is there something wrong with my constraints? 我的约束有问题吗? I'm still learning the auto-layout system, so if there's something in the screenshots that don't help explain my constraints, let me know what I could do to help clarify them. 我仍在学习自动布局系统,因此,如果屏幕截图中有某些内容无法帮助解释我的约束条件,请让我知道我可以做些什么来帮助澄清它们。
I reset the UIImageView
to the suggested constraints and ended up with this at runtime, despite the design-time view looking correct. 尽管设计时视图看起来正确,但我还是将UIImageView
重置为建议的约束,并最终在运行时完成了此操作。
Is there a way for me to constrain the UIImageView so that the image can only grow taller, until it runs out of space to fit the rest of the content? 我是否有办法约束UIImageView,以使图像只能变得更高,直到空间不足以容纳其余内容为止。 I'm missing my bottom label here because now the image is fitting into the UIImageView
but pushing everything else to far down. 我在这里丢失了底部标签,因为现在图像适合UIImageView
但是将其他所有内容推到了最低点。 I'd rather it try to fill as much horizontal space as it can, until the siblings beneath it can no longer be pushed further down. 我希望它尝试填充尽可能多的水平空间,直到它下面的兄弟姐妹不再能够被进一步压低为止。
What I get, vs what i want 我得到的与我想要的
选择您的图像,然后转到“ 布局问题”工具>“重置为建议的约束”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.