iMemon
iMemon

Reputation: 1093

Moving subviews from one view to another view without changing any position information in storyboard?

I have an iOS app in which i have created some view-controller in storyboard, the view-controller's view has some subviews. Now I want to add some scrollview in that view and want to move all those subviews in that scrollview.But the problem is when i drag those views to scrollview, interface builder is centering those subview, all the position information is lost.

I don't want to let interface builder to do that. Isn't there any proper way to solve this problem? I have already searched about this problem and found these two solutions but none is useful in my case.

Adding a subview to the current view without messing up positioning of objects in the view I am unable to use this solution because, this is adding a view into another view while i want to add scrollview.

XCode - Is there a way to drag a component from one view to another without losing its frame? Also this solution is not helpful for me because, storyboard file is messed up and corrupted when i did this.

Upvotes: 28

Views: 9315

Answers (2)

CharlesA
CharlesA

Reputation: 4350

If anyone comes across this question trying to find a way to do this programmatically (as I did), here's what I ended up using:

for (UIView *view in [_viewAdd subviews]) {
    [_viewMain addSubview:view];
}

Note: addSubview removes the view from it's previous superview so there's no need to code for the removal

Upvotes: 4

Alladinian
Alladinian

Reputation: 35626

Yes there is an easy way to do this:

Step 1: Select your views

enter image description here

Step 2: Go Editor > Embed In > Scroll View

enter image description here

Done!

enter image description here

PS. This is a very handy way to group views in fact. You can embed any views into a 'container' view, move it wherever you like (even cross-scene) retaining relative position information and then you could keep it as a group or unembed them.

Upvotes: 62

Related Questions