Featured Post

Applying Email Validation to a JavaFX TextField Using Binding

This example uses the same controller as in a previous post but adds a use case to support email validation.  A Commons Validator object is ...

Monday, October 6, 2014

Code-Free Swipe to a View Controller

In your Cocoa Touch app, you can swipe to a UIViewController using only the Storyboard.  No Objective-C or Swift code is required.
This example adds a Swipe Gesture Recognizer to a UIViewController subclass that navigates to a second UIViewController subclass upon a left swipe.  I've seen examples of doing this on the Web using Objective-C code.  Here is an example that does this using only the Storyboard.

Set Up

This example is from the app "WaySimpleCapitals" which is a US state quiz found on the App Store.  The app has a start screen (Start VC Scene) that is going to navigate to a "hot list" screen which is under construction.  The screenshots are from XCode 6.

Add Swipe Gesture Recognizer

Using the toolbox in the lower-right, lookup Swipe Gesture Recognizer and drag onto the source VC.

Add Swipe Gesture Recognizer

Configure Gesture Recognizer

By default, the Swipe Gesture Recognizer is set to right.  That means a left-to-right drag will activate the recognizer.  In my app's case, I want the opposite action to activate the recognizer.  So, pull up the properties by selecting the Swipe Gesture Recognizer and select "Left".
Change Right Swipe Default to Left

Link the Segue

Finally, you want to navigate to the target VC.  Rather than adding code to make the transition, you can simply drag from the Swipe Gesture Recognizer onto a VC and select "push" to perform the transition without code.
Add a Segue to the Swipe Gesture Recognizer
If you want to extend this example to perform additional processing in the navigation, you can name the segue in Storyboard and refer to this in the prepareForSegue() method.


  1. This caused my app to not load the view controllers that I added touch recognizers to.

    1. Thanks for the heads up. My app doesn't register any recognizers through code so I haven't encountered that problem.

      This is an old post, but I just retested the example on Xcode 7.3.1.