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

How do I use a gesture to switch view controllers?

I have two view controllers and i when the user does a certain gesture on the screen i want it to go to the next view. (like slide up from the bottom, double tap, swipe down etc.)

Junaid,

Wish I could help you, but I've only taken a few iOS courses myself. Hope you find your answer!

1 Answer

Hi Junaid Abdurahman

You can achieve this using UIGestureRecognizer and storyboards as follows:

  • Add your desired gesture in the storyboard, and link that to the relevant IBAction in your view controller.
  • Add a segue in your storyboard by ctrl-click & drag from the viewController of the first view to the viewController of the second view. Make sure that you give it an identifier.
  • In your IBAction function, use performSegueWithIdentifier:sender: to call the segue to the second view controller.

Hope this helps.

Regards, UniekLee