Applying transitions to storyboards

In this recipe, we will look at how we can apply transition animations to views as well as each of the available transitions that come with storyboards.

Getting ready

You may have seen such transitions in applications, such as the photos app that comes as part of the iPhone and iPad, where you can apply a transition and start a slideshow.

How to do it…

In order to configure a segue to specify a kind of transition to use between the different scenes, perform the following simple steps:

  1. Click on the segue link for the first view controller as indicated by the large circle in the following screenshot.
  2. Click on Attributes Inspector and then click on the Transitions drop-down menu.
    How to do it…

You have the ability to choose from the various transition types that are only applicable to the Modal style; these are explained within the following table:

Transition name

Description

Default

When this transition is selected, it uses the Cover Vertical transition style.

Cover Vertical

When the view controller is presented, its view slides up from the bottom of the screen. When the view is dismissed, it slides back down.

Flip Horizontal

When the view controller is presented, the current view initiates a horizontal 3D flip from right to left-hand side, resulting in the revealing of the new view as if it were on the back of the previous view. When this view is dismissed, the flip occurs from left to right-hand side, returning to the original view.

Cross Dissolve

When the view controller is presented, the current view fades out while the new view fades in at the same time. When the view is dismissed, a similar type of cross-fade is used to return to the original view.

Partial Curl

When the view controller is presented, one corner of the current view curls up to reveal the modal view underneath. When the view is dismissed, the curled up page uncurls itself back on top of the modal view. A modal view presented using this transition is itself prevented from presenting any additional modal views.

This transition style is supported only if the parent view controller is presenting a full-screen view and you use the UIModalPresentationFullScreen modal presentation style. Attempting to use a different form factor for the parent view or a different presentation style triggers an exception.

These transitions come as part of the UIViewController class that inherits from the UIKit framework. The UIViewController class provides the underlying fundamental view-management model for all of your iOS apps.

Note

For more information on the preceding transition types, refer to the UIViewController framework reference in the Apple Developer documentation, located at https://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html.

How it works...

Xcode provides the option of changing the visual appearance of the transition as it takes place from one scene to another within a storyboard. These are commonly referred to as segues.

Using transitions enables you to apply a variety of different styles to each of your view controllers that are to be rendered and displayed to the view, and are represented by arrows between each of the view controllers. By default, a Cover Vertical transition is performed whereby the new scene slides vertically upwards from the bottom of the view to cover the currently displayed scene.

You have the ability to define custom transitions that enable you to provide a custom segue class method to handle the transition. This can be achieved by selecting custom for the style of a segue, and fill in the name of the custom segue class to use. If you want to use any of the standard segue classes, you can find these located within the UIKit class.

Note

For information on the standard segue classes, you can refer to the UIKitframework reference in the Apple Developer documentation, located at https://developer.apple.com/library/ios/#documentation/uikit/reference/UIKit_Framework/_index.html.

See also

  • The Preparing transition to another view controller recipe
  • The Presenting storyboard view controllers programmatically recipe
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset