简体   繁体   English

UIImageView忽略UITableViewCell中的AutoLayout约束

[英]UIImageView Ignores AutoLayout Constraints in UITableViewCell

I'm having a problem with a UIImageView inside of a UITableViewCell when using autolayout. 使用autolayout时,我在UITableViewCell内部遇到UIImageView问题。 Specifically I'd like to have the image separated from the edges (20pt) , with a strict size(50pt) and so I have defined this: imageview to top = leading to edgeview = 20 height = width = 50 具体来说,我想将图像与边缘(20pt)分开,具有严格的尺寸(50pt),因此我已经定义了这个:imageview到top =导致edgeview = 20 height = width = 50

在此输入图像描述

What i find is that the imageview completely ignores its constraints(sorry about the scary smiley, it's what google images gave me). 我发现imageview完全忽略了它的限制(抱歉可怕的笑脸,这是谷歌图片给我的)。 Naturally my desired layout would have more content, but regardless of whether that content is present the effect is the same. 当然,我想要的布局会有更多内容,但无论内容是否存在,效果都是一样的。

在此输入图像描述

The setup for the project is as follows: Make a single view app Add a table view, connect the data source and write boilerplate to make at least one cell create a tableviewcell with nib, add an imageview to the tableviewcell constraints to top/leading (10 works, with a height of 20) set an image in the imageview so you can see it at runtime 项目的设置如下:创建单个视图应用程序添加表格视图,连接数据源并编写样板文件以使至少一个单元格创建带有nib的tableviewcell,将tableviewcell约束的imageview添加到top / leading( 10个作品,高度为20)在imageview中设置图像,以便您可以在运行时看到它

I feel like that should be sufficient, but it seems not to be working, am I missing something silly? 我觉得这应该足够了,但似乎不起作用,我错过了一些愚蠢的东西吗? For comparison this same setup causes no problem without a tableview, the imageview behaves just the way expected 为了进行比较,如果没有tableview,这个相同的设置没有问题,imageview的行为就像预期的那样

事实证明我错过了保持Anna版本工作的一步,我已经将UIImageView与一个名为imageView的属性连接起来(覆盖了UITableViewCell的默认属性),显然超类中的约束比我添加的更强。

I couldn't quite get this to work myself, but I think you'll get it if you try some of the things in here: 我自己无法完成这项工作,但我认为如果你在这里尝试一些东西,你会得到它:

Using Auto Layout in UITableView for dynamic cell layouts & variable row heights 在UITableView中使用自动布局来获取动态单元格布局和可变行高

I think that it doesn't ignore it.Your setup is correct. 我认为它不会忽略它。你的设置是正确的。 You just have to stop drawing outside image view. 您只需要停止绘制外部图像视图。 Check this on ImageView: Clip Subviews ->enabled. 在ImageView上检查:剪辑子视图 - >启用。 Choose also good View fill mode: Scale To Fill or Aspect Fit. 选择好的视图填充模式:缩放到填充或纵横比适合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM