iOS Developer Library

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. More...

Inheritance


Not Applicable

Import Statement


import UIKit @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

    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

    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

    import UIKit

    Availability

    Available in iOS 7.0 and later.