4

我很好奇是否有可能向最近的可见(未隐藏)邻居添加约束。

想象一下,我有 3 个 UIView:

[视图1]-[视图2]-[视图3]

假设每个视图之间当前有 10 像素。

我想要的是 view1 距离最近的可见邻居 10px。所以当我隐藏view2时,view3会靠得更近,这样view1和view3之间就只有10px了。

这可以通过 AutoLayout 约束实现吗?

4

1 回答 1

4

A way to achieve this is to create an IBOutlet in the controller and associate your second view’s width constraint with it. Whenever you need to hide view2, modify the constant property of the constraint instead and set it to 0. Whenever you need to show the view back, restore the value of the constraint. This way view3 will dynamically move around.

于 2015-02-24T10:36:15.780 回答