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

Container View (Swift)

So, I've been racking my brain for a couple days now. My goal is to have a main view, then swipe right to go to the next view, and again for the 3rd (the information in the 2nd and 3rd views are related to the main view, and will change daily), which seems to me like one of the most common features in most apps. Creating segues to other view controllers via buttons or tabs is super easy (just click and drag), but for some reason they make this common feature stupidly complicated for something that should be just as easy as simple segues in the storyboard.

I first started out researching the page view controller, only to find out that's not what I wanted and was too annoying to work with.

I think I found out that Container View is what I need, creating child views and what not. Does anyone know a good step by step tutorial to show you how to set all this up in the storyboard, like, a dummy's guide? I'm a severe novice, so a lot of the docs people point me towards might as well be ancient Egyptian hieroglyphics.

someone please help a frustrated beginner? :)

5 Answers

So you're looking for custom transitions between view controllers? No idea how to manipulate this in Swift, but you could scour the interwebs for "custom transitions between view controllers in swift" or something of the like. There's a WWDC video on this (in obj-C) here.

Something else here which should be pretty close to what you're looking for.

Check out objc.io's tutorial on custom transitions as well. I believe they have the code written in both Swift and Objective-C.

not necessarily custom transitions, I just want it to swipe to the next view (like snapchats user interface). I'll check out the links you provided!

You could create a collection view with an item number of x number of views you want to manipulate and size each cell to the bounds of the view of the target device. Enable paging for the collection view to get the same scrolling effect as snapchat.

Could you give steps on how to actually do that...? :)

Haha. Well, I wouldn't feel comfortable giving you a step-by-step, but I could guide you in the right direction if you get stuck. Go through a few lessons on treehouse and search the web for info on how to start up a collection view and figure out what it is you have to do to achieve what you want.

Hey @TaylorSmith, I've been trying to figure out the same thing though haven't quite come to a conclusion. I do know that you need to use container views, though the next challenge is trying to link more than one view controller to a container view. CVs normally only let you embed 1 VC, so there is a code solution. I'd be interested in hearing if you have come up with a solution.