ER: Option to embed in view preserving constraints and positions

Originator:jscalo
Number:rdar://35106222 Date Originated:10/20/2017
Status:Duplicate Resolved:
Product:Developer Tools Product Version:
Classification:Suggestion Reproducible:
 
Currently (and since forever) when you Editor > Embed in View, Xcode seriously mangles existing constraints and frames. Specifically, it shifts everything over and up by 20 pts and destroys all constraints to the old superview.

As evidenced by horrendous hacks such as http://indiestack.com/2013/12/transplanting-constraints/, and StackOverflow traffic e.g. https://stackoverflow.com/questions/22738386/embed-views-in-super-view-without-losing-autolayout-constraints, there's demand for a method of embedding one view into another without losing constraints.

I propose the following: when holding down the Option key, change the View and ScrollView in the Embed menu to "View (preserving constraints)" and "ScrollView (preserving constraints)". When selecting those options Xcode does the following:

* Creates a new container view (or scroll view) that exactly fits the frames of the selected views. (No 20 pt padding.)
* Transplants all constraints of the selected views from the prior superview to the new container view.

The upshot is that you'd be able to take subviews in one view and move them to a container view with a single menu selection without disturbing the appearance or position of those subviews.

I promise you'd collectively save the iOS dev community _years_ of time if you added this.

Thanks for listening :-)

Comments

Duplicate of 33322429.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!