George Cook
George Cook

Reputation: 180

Drag and move something in Interface builder, without changing parent/superview

I have some views in interace builder. I have a background view that takes up my entire view area and above it I have some buttons which are NOT in the background view.

I want to drag those around to reposition them; but when I do, IB will reparent them when I let go of them.

That is to say, IB seems to only understand drag/drop in this case as a reparenting action; not a moving action.

Is there a hotkey, or something I can do to make IB just move things, without changing the parent when I let go?

This has to be the most painful part of working with IB for me.

Upvotes: 9

Views: 2574

Answers (3)

EPage_Ed
EPage_Ed

Reputation: 1183

If you hold the command key down while dragging, the dragged element will not change superviews. At least in Xcode 7.3.

Upvotes: 12

Ken Boreham
Ken Boreham

Reputation: 904

This has been bothering me as well. I've found a workaround which I find slightly less annoying. Sounds like a lot but it's really quite easy.

  • Select the item you want to move
  • Goto Editor -> Embed In -> View (this creates a parent view for your item)
  • Resize (but don't move) the parent view to encompass the area you want to move to
  • Move the item within the parent view
  • Select the parent view and Goto Editor -> unembed

Also, since resizing doesn't cause the parent to change you could actually move a view with two resizes. However it's tedious to get the size right again which is why I like the embed method.

Upvotes: 6

Loc Pham
Loc Pham

Reputation: 617

You can press function key and drag the object: Fn + drag

Upvotes: -1

Related Questions