iOS Developer Library — Pre-Release

Developer

UIKit Framework Reference UIViewControllerAnimatedTransitioning Protocol Reference

Options
Deployment Target:

On This Page
Language:

UIViewControllerAnimatedTransitioning

Adopt the UIViewControllerAnimatedTransitioning protocol in objects that implement the animations for a custom view controller transition. The methods in this protocol let you define an animator object, which creates the animations for transitioning a view controller on or off screen in a fixed amount of time. The animations you create using this protocol must not be interactive. To create interactive transitions, you must combine your animator object with another object that controls the timing of your animations.

In your animator object, implement the transitionDuration: method to specify the duration of your transition and implement the animateTransition: method to create the animations themselves. Information about the objects involved in the transition is passed to your animateTransition: method in the form of a context object. Use the information provided by that object to move the target view controller’s view on or off screen over the specified duration.

Create your animator object from a transitioning delegate—an object that conforms to the UIViewControllerTransitioningDelegate protocol. When presenting a view controller, st the presentation style to UIModalPresentationCustom and assign your transitioning delegate to the view controller’s transitioningDelegate property. The view controller retrieves your animator object from the transitioning delegate and uses it to perform the animations. You can provide separate animator objects for presenting and dismissing the view controller.

To add user interaction to a view controller transition, you must use an animator object together with an interactive animator object—a custom object that adopts the UIViewControllerInteractiveTransitioning protocol. For more on defining interactive transitions, see UIViewControllerInteractiveTransitioning Protocol Reference.

Inheritance


Not Applicable

Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 7.0 and later.
  • Tells your animator object to perform the transition animations. (required)

    Declaration

    Swift

    func animateTransition(_ transitionContext: UIViewControllerContextTransitioning)

    Objective-C

    - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext

    Parameters

    transitionContext

    The context object containing information about the transition.

    Discussion

    UIKit calls this method when presenting or dismissing a view controller. Use this method to configure the animations associated with your custom transition. You can use view-based animations or Core Animation to configure your animations.

    All animations must take place in the view specified by the containerView property of transitionContext. Add the view being presented (or revealed if the transition involves dismissing a view controller) to the container view’s hierarchy and set up any animations you want to make that view move into position. If you want to draw to the screen directly without a view, use this method to configure a CADisplayLink object instead.

    You can retrieve the view controllers involved in the transition from the viewControllerForKey: method of transitionContext. For more information about the information provided by the context object, see UIViewControllerContextTransitioning Protocol Reference.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Tells your animator object that the transition animations have finished.

    Declaration

    Swift

    optional func animationEnded(_ transitionCompleted: Bool)

    Objective-C

    - (void)animationEnded:(BOOL)transitionCompleted

    Parameters

    transitionCompleted

    Contains the value YEStrue if the transition completed successfully and the new view controller is now displayed or NOfalse if the transition was canceled and the original view controller is still visible.

    Discussion

    UIKit calls this method at the end of a transition to let you know the results. Use this method to perform any final cleanup operations required by your transition animator when the transition finishes.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Asks your animator object for the duration (in seconds) of the transition animation. (required)

    Declaration

    Swift

    func transitionDuration(_ transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval

    Objective-C

    - (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext

    Parameters

    transitionContext

    The context object containing information to use during the transition.

    Return Value

    The duration, in seconds, of your custom transition animation.

    Discussion

    UIKit calls this method to obtain the timing information for your animations. The value you provide should be the same value that you use when configuring the animations in your animateTransition: method. UIKit uses the value to synchronize the actions of other objects that might be involved in the transition. For example, a navigation controller uses the value to synchronize changes to the navigation bar.

    When determining the value to return, assume there will be no user interaction during the transition—even if you plan to support user interactions at runtime.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.