Xcode - Is there a way to drag a component from one view to another without losing its frame?

前端 未结 9 536
无人及你
无人及你 2020-12-04 07:22

What I\'d like to do is drag a component/view from one superview to another in Xcode\'s interface-builder without having its frame/position be reset.

Xcode\'s defa

9条回答
  •  温柔的废话
    2020-12-04 08:09

    Xcode Interface Builder messes when a Parent View is dragged and dropped into another View (UIView, ScrollView, StackView)

    Q:
    Embedding a View (which contains many other subviews within it) into a ScrollView or in another top level view is not straight forward with what I have seen so far. What happens soon after is all the subviews might seems to be misplaced due to it couldn’t find their original frame.

    A:
    Follow following steps and you will be able to resolve it easier as possible:

    1. Select the items you want in your subview, then
    2. Go to menubar, Editor -> Embed In -> View
    3. Copy this new View (Cmd+C) with the subviews (for me currently all the constraints were preserved so far at this point)
    4. Go to the view (be it a ScrollView or may be StackView) you want the subviews to be in and paste (Cmd+V) the copied view
    5. Select the pasted Embedding View (which you newly created previously) and Go to menubar of Xcode, Editor -> Unembed

    No, not finished yet! Sometimes, you may experience that there are few more UI Constraint related issues, you will have to resolve them accordingly.

提交回复
热议问题