gpt4 book ai didi

ios - 为什么自动布局忽略了一些约束?

转载 作者:行者123 更新时间:2023-12-01 16:32:37 26 4
gpt4 key购买 nike

该应用程序有一个简单的 TableView Controller ,可以在左侧显示图像。 (见第一张图片)。 UIView与 x 轴对齐,具有前导空间约束,并且具有最大宽度。我本以为这也足以防止图像失真超过 130 像素,但事实并非如此。当设备处于横向模式时,问题更加明显。

为什么忽略某些约束(请参阅 View 调试器屏幕截图中的某些约束如何变灰),更重要的是,如何才能使具有固定高度的可变宽度图像在单元格中不失真?

Autolayout all blue and not complaining

some of the constraints are being greyed out

in landscape mode the problem is more clearly visible.

最佳答案

您问了两个问题,我将分别回答:

  • 为什么有些约束被忽略:

  • 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/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com