Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Hide UIView using Autolayout

I have the following structure in my app:

[topView] [middleView] [bottomView]

I want to be able to hide/show the middleView when the user taps on a button. Im using nsconstraints and and Im adjusting the height constraint to 0 when I need to hide the middleView. And then set it back to 40 when I need to show the view. This works when middleView has no subviews. How do I deal with this when subviews are involved?

1 Answer

Maybe this method would work for you.

sendSubViewToBack

Otherwise keep reading in the UIView class reference.

The [middleView] has subviews, so if I set the constraint to 0, I get a NSConstraints error cause the children have no way of knowing how to adjust. If I send them to the back they will still be there.