Question

My problem is related to the use of autolayout (the famous) ;)

I would like to manage 2 situations of subviews in the same view controller so that I can go from one situation to another (and reciprocally).

Let me introduce the problem with the following diagram :

Diagram of the same view controller in the 2 situations

The problem is that I can't figure how to express the autolayout constraints in Interface Builder so that I can easily switch from one situation to another. To be more precise the subviews VIEW_B1 and VIEW_B2 are differents subviews with different height.

I already try to hide the subview I don't want to see (either VIEW_B1 or VIEW_B2) but in this case the VIEW_C will remains at its Y position. What I'd like it's VIEW_C to be glue to the VIEW_B* (the one that is not hidden).

Was it helpful?

Solution

Hiding the view doesn't remove the constraints. You have to remove view B1 from its superview, insert B2 and then add constraints pinning B2 to the views above and below it.

If you don't want to remove the view altogether, you can store the constraints linking each B* view to the views above and below it in properties, and then when you switch out the views, remove and add the appropriate constraints to the superview.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top