解释 iOS 中的宽高比和相应术语?

Explain Aspect Ratio and respective terms in iOS?

我想了解宽高比。

在这里,我正在设置 UIImageView 的纵横比。

这些是我单击此约束时的选项。

此约束的工作原理以及什么是 "PRESETS"、反转乘数和转换为小数。

谢谢。

If you select Aspect Ratio for a single item, the width of the item is used as the numerator for the ratio, and the height is used for the denominator. If you select Aspect Ratio for multiple items, Auto Layout chooses the width of one of the items for the numerator and the height of another item for the denominator. To change the initial aspect ratio, edit the Multiplier field of the Attributes inspector for the constraint. To change which item to use for the width or the height, use the First Item and Second Item pop-up menus in the Attributes inspector.

阅读更多 here

纵横比约束用于根据您在此处设置的纵横比来控制视图的宽度和高度。有一些标准预设,例如 1:1,这意味着宽度将等于高度。类似地,其他预设基于比率

计算尺寸

Reverse Multiplier只是用来反转比例。例如。 4:3 将是 3:4 转换为小数只是将比率表示为小数。例如。 4:3 将是 1.33

如果您希望视图始终保持纵横比,则可以使用此约束。在您的情况下,如果它的图像视图并且您知道将要设置的图像的纵横比,那么您可以将该纵横比设置为约束,以便图像始终根据设置为该图像视图的图像调整大小,

约束类似于数学中的方程式。

例如:

X- known value (20)

Y- Unknown value (?)

m- multiplier (like 2 or 3 times)

C- constant (+3 or -3)

我们使用这个方程来计算 Y 值。

Y = m * X + C

Y = 2 * 20 + 3

Y=43

约束方程:

第一个对象 =(乘数 * 第二个对象)+ 常量

宽度 = (0.5 * 高度) + 20

在纵横比条件下

注意:必须固定一个值(高度或宽度)

A) 预设

1)宽=1*高

宽度/高度 = 1/1 (1:1)

2)宽度 = 3/4 * 高度

宽度/高度 = 3 / 4 (3:4)

B) 反向乘数

反转前

宽度 = 1/2 * 高度 (1:2)

反转后

宽度 = 2/1 * 高度 (2:1)

C) 转换为十进制

转换前

宽度 = 1/2 * 高度

转换后

宽度 = 0.5 * 高度 (0.5)