Is there a way for Embed in -> to inherit / copy over existing constraints?

Is there a way for Embed in -> to inherit / copy over existing constraints?


Basically, say I have a UIView, and I set it to 20 from top / leading / trailing / bottom.


Then later, I decide I want to embed that in another UIView. Using the embed in menu it loses all of its constraints. Is there a easy way to keep the constraints and it just remaps them from Superview to my new UIView? I know this is a simple example but think a UIView with labels, text, etc, etc all positioned to the safespace, and when I select them and embed in a UIView it essentially destroys all the previous work and makes me start over reconnecting all my constraints. I can see how sometimes it wouldn't make sense to keep the constraints, but it really would be nice to reapply as many relevant constraints as possible. Is there something I am missing that would make this type of process easier? even 3rd party or some other method I am overlooking?


Thanks!

Replies

I don't think you can do it in IB.


And unfortunately, that cannot be achieved in code with IBOutlets for constraints, as constraints disappear when you embed.


but it really would be nice to reapply as many relevant constraints as possible.

However, constraints between objects that you embed are preserved. So, you would have only one set of constraints to redefine for the "lead object".

Did you solve your issue ?

> Is there a easy way to keep the constraints and it just remaps them from Superview to my new UIView?


Child views inherit constraints from the parent. Did you try not setting any at all?