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)
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.
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.
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.
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 embed
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With