6

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)

Yuan Fu
  • 310
  • 2
  • 14

1 Answers1

5

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.

Er. Khatri
  • 1,384
  • 11
  • 29
  • That's the thing that OP is trying to avoid i.e. setting up the constraints that were dependant on the superview – Malik Sep 07 '17 at 05:01
  • As the question clearly specifies "I found all of these constraints disappear". So using this your all constraints will not disappear.., depending on their relativity... Even many of constraints will remain there only a few needs to add again @Malik – Er. Khatri Sep 07 '17 at 06:47
  • @ Er. Khatri Did you have a look at the screenshots shared by the OP? The constraints that were removed were in fact the ones dependant on it's superview – Malik Sep 07 '17 at 06:55
  • Hi, Er.Khatri and @Malik . Finally, I solved this problem. I was using [UIScrollView Scrollable Content Size Ambiguity](https://stackoverflow.com/questions/19036228/uiscrollview-scrollable-content-size-ambiguity) to solve it. First, put a new view controller and put a scroll view, and then put a **view** into scroll view. Secondly, I copy children views from first controller into this **view**. Although, they will missing constraints which related to superview, but only need to add these constraints instead of reset all constraints. Thank you so much, both of you. – Yuan Fu Sep 07 '17 at 07:02
  • @YuanFu what you did is the same which xcode does for us.. if you have selected embed in -> View you would get a new view.. so always you can be hassle free by letting xcode do the task for you. Well Kudos finally your problem is solved.. – Er. Khatri Sep 07 '17 at 07:17