Reputation: 4619
I was curious if it is possible where I can add a constraint to the nearest visible (unhidden) neighbor.
Imagine that I have 3 UIViews:
[view1]-[view2]-[view3]
Lets say there's currently 10px between each views.
What I want is for view1 to be 10px from the nearest visible neighbor. So when I hide view2, view3 will move closer so that there will only be 10px between view1 and view3.
Is this possible via AutoLayout constraints?
Upvotes: 4
Views: 1234
Reputation: 6247
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.
Upvotes: 4