自动布局理解乘数 [英] AutoLayout Understanding Multiplier

查看:59
本文介绍了自动布局理解乘数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对乘法器有疑问,无法理解此功能的工作原理.例如,我的视图具有以下6:1乘数(到SuperView.Leading).

I have a problem with multiplier and cannot understand how this feature works. For example i have view has 6:1 multiplier(To SuperView.Leading) as below.

当我将乘数更改为2:1时,如下图所示.

When i change the multiplier to 2:1 it seems like below picture.

我的问题是在6:1关系中6和1是什么意思.而且在2:1关系中2和1是什么意思.类似地考虑您具有如下图所示的三个视图.在subViews和superView之间总共有4个空白区域.我怎么能说每个空白区域必须是SuperView.Width/6(每个空白宽度必须相等)

My question is in the 6:1 relation what does 6 and 1 mean. And also in 2:1 relation what does 2 and 1 mean. Similar consider you have three view like the picture below. Totally there 4 blank areas between subViews and superView. How can i say every blank area must be the SuperView.Width / 6 (and every blank width must be equal)

谢谢.

推荐答案

在使用自动布局时,尤其是在使用比例布局时,必须使用乘数.

When working with autolayout, especially when you are working with proportional layouts, you have to use multiplier.

我必须在这里解释一些数学. 我们知道直线方程.

I have to explain here some mathematics. We know straight line equation.

Y = Mx + C

Y = Mx + C

在上式中.假设M是您的乘数,C是您的常数.

In above equation. Assume M is your multiplier and C is your Constant.

因此,假设您具有以下内容的超级观看权限(在iPhone 6s plus的情况下) 414(宽)x 736(高)的尺寸.假设您在该视图上创建了子视图.

Thus suppose you have superview (in case of iphone 6s plus) of 414(width) x 736(height) size. On that view suppose you created subview.

现在,如果您希望子视图的大小大约是超级视图大小的一半,那么只需将两个约束从子视图拖到超级视图即可. (即宽度相等和高度相等)

Now if you want subview size exacly half of superview size, then just drag two constraints from subview to superview. (i.e. Equal Width and Equal Height)

查看此图片

很显然,现在您会得到一个错误.就像我要. (请参见下图)

Obviously now you will get an error. just like I'm getting. (See below Image)

现在一对一单击两个约束,并将乘数设为0.5.然后使用上面的直线方程. 这里的0.5表示您希望subview的宽度= superviewWidth/2.0,即207 px.

Now click on both of the constraints one by one, and use multiplier as 0.5. Then use above straight line equation. Here 0.5 means you want width of subview = superviewWidth / 2.0 i.e. 207 px.

换句话说,您也可以将乘数设为207:414.

In other words you can provide multiplier as 207:414 also.

Y即subviewWidth =((M即0.5)*(x即414即superviewWidth))+(常数即零)

Y i.e. subviewWidth = ((M i.e. 0.5) * (x i.e. 414 i.e. superviewWidth)) + (Constant i.e. Zero)

最后,您得到subviewWidth = 207 px

Finally you get subviewWidth = 207 px

类似地对子视图的高度进行操作.提供乘数0.5或368:736.

Similarly do for height of subview. Provide multiplier 0.5 or 368:736.

完成所有操作后,请不要忘记单击子视图并更新框架.

这样常数和乘数将起作用.

This way constants and multiplier will works.

这篇关于自动布局理解乘数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆