6.4. Introducing Custom Segue Transitions to Your Storyboard

Problem

You want to introduce and use a new type of storyboard transition in your storyboard files so that the move from one view controller to another is done in a custom way—for instance, with a custom animation.

Solution

Subclass UIStoryboardSegue and override its perform method to do your work.

Discussion

Storyboards, by default, offer a few useful segue types, such as push and modal. These are great, but sometimes you may wish to perform a custom transition from one view to the other. In these cases, it’s best to use a custom segue object. Let’s create a segue, then. What we are going to do here is allow the first view controller to display the second view controller with a flip transition. To do this, follow these steps:

  1. Create a project based on the Single View Application template in Xcode.

  2. In your storyboard file, create a second view controller and place a button in the center of the first view controller. Hold down the Ctrl button on your keyboard and drag and drop from the button onto the second view controller. At this point, a dialog will appear on your screen asking what type of transition you want to associate with this segue. In that dialog, choose “custom” (see Figure 6-14).

Associating a custom segue with the action of our button

Figure 6-14. Associating a custom segue with the action of our button

  1. Now select your segue, and in the Attributes Inspector in Interface Builder, ...

Get iOS 7 Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.