Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AutoLayout, put all views into a new parent view

I had defined all views and had sets its constraints with superview in a view controller, but now I want to put all these children views into a Scrollview, I found all of these constraints disappear. Is there any good ways to make it easier to do, instead of reset all of these constraints?

Following the pictures showed on below:

Origin constraints

Now, when I drag all these views into ScrollView, all constraints disappear

Missing all constraints

(sorry these two links are screenshots, I don't have 10 reputation to post images)

like image 446
Yuan Fu Avatar asked Sep 07 '17 04:09

Yuan Fu


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.

How to add constraints to view in Xcode?

In Xcode 7.2 (and perhaps also in your version of Xcode), firstly select the view that you want to add constraint to, and then press the "control" button on your keyboard and keep doing it, and then drag the view to the super-view. Then a menu will appear, and then you can select to add some constraints.

What is constraint to margin in Xcode?

Basically if the layout margins are 8,8,8,8 (the default), a constraint with 0 leading space to container margin will have an x position of 8. Note that this is only available on iOS8 or later.


1 Answers

simply select your UIElements which you want to be the child of UIScrollView., Now go to editor -> Embed In -> UIScrollView Now your child viewcontrollers will be emebedded with scrollview with all constraints except the constraints which were dependent on its superview. Here's a image of how to select and embedEmbed Elements

The constraints which were dependent on superview layoutguide, you'll need to make them again with uiscrollview., add add constraint to scrollview with its superview.

like image 196
Er. Khatri Avatar answered Nov 02 '22 04:11

Er. Khatri