该应用程序有一个简单的 TableView Controller ,可以在左侧显示图像。 (见第一张图片)。 UIView
与 x 轴对齐,具有前导空间约束,并且具有最大宽度。我本以为这也足以防止图像失真超过 130 像素,但事实并非如此。当设备处于横向模式时,问题更加明显。
为什么忽略某些约束(请参阅 View 调试器屏幕截图中的某些约束如何变灰),更重要的是,如何才能使具有固定高度的可变宽度图像在单元格中不失真?
最佳答案
您问了两个问题,我将分别回答:
They aren't being ignored actually. You have not set any constraints for those specific areas. When you apply a constraint, a respective line is highlighted in blue. When you haven't applied a constraint for a specific side, it remains grey.
You can use either AspectFit or AspectFill, so that the aspect ratio of your images is not disturbed and they don't looks stretched.
You should also remove the width constraint from the ImageView. Then you can use AspectFill if you know that your height will not increase from 130. If your image height can be more than 130, you should rather use AspectFit.
关于ios - 为什么自动布局忽略了一些约束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30998828/