简体   繁体   English

使用乘数进行尾随但不加前导的快速约束

[英]Swift constraint using multiplier working with trailing but not leading

I have the following two texts the Timer constraint works fine. 我有以下两个文本,Timer约束工作正常。 However when doing the complete same with Score just using leading constraint it's stuck. 但是,当仅使用前导约束对Score进行完全相同时,就会卡住。

Anyone has an idea what I'm missing? 有人知道我想念什么吗?

在此处输入图片说明 在此处输入图片说明

Because leading has zero value unlike trailing which = view width , so applying multiplier to zero results in a zero 由于前导的值为零,与尾随的=视图宽度不同,因此将乘数应用于零将导致零

You can make it with centerX / trailing also 您可以使用centerX /尾随它

在此处输入图片说明

Just change the leading Constrain of Score to Superview.Trailing instead of Superview.Leading : 只需将领先的分数约束更改为Superview.Trailing而不是Superview.Leading:

在此处输入图片说明

And then set the Score constraint multiplier to 6.27. 然后将“得分约束”乘数设置为6.27。 I will update the answer with the calculation I made shortly. 我将使用不久后进行的计算来更新答案。

UPDATE: 更新:

The multiplier of Score.Leading constant to Superview.Traling constant is : multiplier = View.width / (View.width - View.width / 1.2) Score.Leading常数与Superview.Traling常数的乘数为:乘数= View.width /(View.width-View.width / 1.2)

In my case the View width in iPhone X is 414 以我为例,iPhone X的“查看宽度”为414

414 / 1.2 = 345 414 / 1.2 = 345

414 - 345 = 69 414-345 = 69

414 / 69 = multiplier 414/69 =乘数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM