如何解决更改由autolayout计算的宽度的问题?

时间:2016-06-10 14:02:00

标签: ios autolayout

问题:

当您使用autolayout将宽度设置为" mutipliedBy"与某事物的关系或设定为精确值(例如131),它在沿X轴移动时会发生变化。

示例:

我将视图的宽度设置为(131.0f)。然后我沿着X轴移动视图:

2016-06-10 16:58:30.961 {{6, 40}, {130.5, 196.5}}
2016-06-10 16:58:31.095 {{5.5, 40}, {130.5, 196.5}}
2016-06-10 16:58:31.212 {{5.5, 40}, {130.5, 196.5}}
2016-06-10 16:58:31.362 {{5, 40}, {130.5, 196.5}}
2016-06-10 16:58:31.536 {{5, 40}, {130.5, 196.5}}
2016-06-10 16:58:31.692 {{3.5, 40}, {130.5, 196.5}}
2016-06-10 16:58:31.791 {{3.5, 40}, {130.5, 196.5}}
2016-06-10 16:58:31.833 {{3, 40}, {130.5, 196.5}}
2016-06-10 16:58:31.864 {{3, 40}, {130.5, 196.5}}
2016-06-10 16:58:31.930 {{2.5, 40}, {130.5, 196.5}}
2016-06-10 16:58:31.978 {{2.5, 40}, {130.5, 196.5}}
2016-06-10 16:58:32.045 {{2, 40}, {130.5, 196.5}}
2016-06-10 16:58:32.129 {{2, 40}, {130.5, 196.5}}
2016-06-10 16:58:32.195 {{1.5, 40}, {130.5, 196.5}}
2016-06-10 16:58:32.330 {{1.5, 40}, {130.5, 196.5}}
2016-06-10 16:58:32.516 {{0, 40}, {130.5, 196.5}}
2016-06-10 16:58:32.648 {{-0.5, 40}, {131, 177.5}}
2016-06-10 16:58:32.764 {{-0.5, 40}, {130.5, 196.5}}
2016-06-10 16:58:32.812 {{-1, 40}, {131, 177.5}}
2016-06-10 16:58:32.930 {{-1, 40}, {130.5, 196.5}}
2016-06-10 16:58:33.194 {{-1.5, 40}, {131, 177.5}}
2016-06-10 16:58:34.468 {{-1.5, 40}, {130.5, 196.5}}
2016-06-10 16:58:34.760 {{-2, 40}, {131, 177.5}}
2016-06-10 16:58:35.881 {{-2, 40}, {130.5, 196.5}}
2016-06-10 16:58:36.166 {{-2.5, 40}, {131, 177.5}}
2016-06-10 16:58:36.444 {{-3.5, 40}, {130.5, 196.5}}
2016-06-10 16:58:37.230 {{-4, 40}, {131, 177.5}}
2016-06-10 16:58:38.663 {{-4, 40}, {130.5, 196.5}}
2016-06-10 16:58:39.847 {{-4.5, 40}, {131, 177.5}}
2016-06-10 16:58:42.068 {{-4.5, 40}, {130.5, 196.5}}
2016-06-10 16:58:42.498 {{-5, 40}, {131, 177.5}}
2016-06-10 16:58:42.762 {{-5, 40}, {130.5, 196.5}}
2016-06-10 16:58:42.906 {{-5.5, 40}, {131, 177.5}}
2016-06-10 16:58:43.096 {{-5.5, 40}, {130.5, 196.5}}
2016-06-10 16:58:43.232 {{-6, 40}, {131, 177.5}}

如您所见,仅当origin.x为负时,宽度才会发生变化。

可能的解决方案:

我可以在updateConstraints中自己计算宽度(在我的情况下它可以接受),但也许有人有更好的解决方案。

0 个答案:

没有答案