我对乘数有疑问,无法理解此功能的工作原理.例如,我的视图有 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
在上面的等式中.假设 M 是您的乘数,C 是您的常数.
In above equation. Assume M is your multiplier and C is your Constant.
因此假设你有 superview(在 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 表示您想要子视图的宽度 = superviewWidth/2.0 即 207 像素.
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 i.e. 0.5) * (x i.e. 414 i.e. superviewWidth)) + (Constant i.e. 0)
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.
这篇关于AutoLayout 理解乘数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!