Can I specify an AutoLayout restriction on iOS for the distance to the nearest visible neighbor?

I was curious if it is possible when I can add a restriction to the nearest visible (unclosed) neighbor.

Imagine I have 3 UIViews:

[view1] - [view2] - [View3]

Suppose there are currently 10 pixels between each views.

I want view1 to be 10px from the nearest visible neighbor. So when I hide view2, view3 will move closer, so there will only be 10px between view1 and view3.

Is this possible with AutoLayout restrictions?

+4
source share
1 answer

To do this, you need to create an IBOutlet in the controller and bind the width of the second view to it. Whenever you need to hide view2 , change the constant property of this restriction and set it to 0 . When you need to display the view back, restore the restriction value. This way view3 will move dynamically.

+4
source

Source: https://habr.com/ru/post/1499693/


All Articles