Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 660
iMemon Avatar asked Jun 06 '13 08:06

iMemon


People also ask

How do you use auto layout to move other views when a view is hidden?

You need to set the compression resistance priority to 0 (not the content hugging) in code when you want to hide the view, and when you want to show again restore that value. Apart of that you need to add a constraint in interface builder to set the size of the view to 0.

What method or methods do you call to add a subview to another view?

To add a subview to another view, call the addSubview(_:) method on the superview.

What is a UIView?

UIView can be defined as an object by using which we can create and manage the rectangular area on the screen. We can have any number of views inside a view to create a hierarchical structure of the UIViews. The UIView is managed by using the methods and properties defined in the UIView class that inherits UIKit.


1 Answers

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.

like image 58
Alladinian Avatar answered Oct 14 '22 01:10

Alladinian