iOS Developer Library — Pre-Release

Developer

UIKit Framework Reference UIViewControllerTransitioningDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

UIViewControllerTransitioningDelegate

An object that implements the UIViewControllerTransitioningDelegate protocol vends the objects used to manage a fixed-length or interactive transition between view controllers. When you want to present a view controller using a custom modal presentation type, set its modalTransitionStyle property to UIModalPresentationCustom and assign an object that conforms to this protocol to its transitioningDelegate property. When you present that view controller, UIKit queries your transitioning delegate for the objects to use when animating the view controller into position.

When implementing your transitioning delegate object, you can return different animator objects depending on whether a view controller is being presented or dismissed. All transitions use a transition animator object—an object that conforms to the UIViewControllerAnimatedTransitioning protocol—to implement the basic animations. A transition animator object performs a set of animations over a finite period of time. If you want to use touch input or other user interactions to control the timing of the animation, you can also provide an interactive animator object—an object that conforms to the UIViewControllerInteractiveTransitioning protocol—to update the progress of the animations. You can provide separate animator objects for presenting and dismissing the view controller.

For custom modal transition styles, you can provide a UIPresentationController object in addition to the animator objects. The system creates your presentation controller before presenting the view controller and keeps a reference to that object until the view controller is dismissed. Because its existence extends beyond the lifespan of either animator object, you can use the presentation controller to coordinate aspects of the presentation or dismissal process that would be difficult to do otherwise. For example, if your custom transition style involves displaying a separate shadow view as a backdrop to the view controller’s content, the presentation controller can create the shadow view and show it and hide it at the appropriate times.

Inheritance


Not Applicable

Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 7.0 and later.
  • Asks your delegate for the transition animator object to use when presenting a view controller.

    Declaration

    Swift

    optional func animationControllerForPresentedController(_ presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning?

    Objective-C

    - (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source

    Parameters

    presented

    The view controller object that is about to be presented onscreen.

    presenting

    The view controller that is presenting the view controller in the presented parameter. The object in this parameter could be the root view controller of the window, a parent view controller that is marked as defining the current context, or the last view controller that was presented. This view controller may or may not be the same as the one in the source parameter.

    source

    The view controller whose presentViewController:animated:completion: method was called.

    Return Value

    The animator object to use when presenting the view controller or nil if you do not want to present the view controller using a custom transition. The object you return should be capable of performing a fixed-length animation that is not interactive.

    Discussion

    Use this method to create and return an object that implements the methods of the UIViewControllerAnimatedTransitioning protocol. Your implementation of that protocol must animate the appearance of the presented view controller’s view onscreen. Use the presented, presenting, and source parameters to initialize your animator object or perform any tasks necessary to prepare the transition animations. You may return nil from this method if you do not want to implement a custom transition animation for the specified set of view controllers.

    For information on implementing your transition animator object, see UIViewControllerAnimatedTransitioning Protocol Reference.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Asks your delegate for the transition animator object to use when dismissing a view controller.

    Declaration

    Swift

    optional func animationControllerForDismissedController(_ dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning?

    Objective-C

    - (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed

    Parameters

    dismissed

    The view controller object that is about to be dismissed.

    Return Value

    The animator object to use when dismissing the view controller or nil if you do not want to dismiss the view controller using a custom transition. The object you return should be capable of performing a fixed-length animation that is not interactive.

    Discussion

    Use this method to create and return an object that implements the methods of the UIViewControllerAnimatedTransitioning protocol. Your implementation of that protocol must animate the disappearance of the dismissed view controller’s view from the screen. Use the dismissed parameter to initialize your object or perform any tasks necessary to prepare the transition animations. You may return nil from this method if you do not want to implement a custom transition animation when dismissing view controllers.

    For more information on implementing a transition animator object, see UIViewControllerAnimatedTransitioning Protocol Reference.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Asks your delegate for the custom presentation controller to use for managing the view hierarchy when presenting a view controller.

    Declaration

    Swift

    optional func presentationControllerForPresentedViewController(_ presented: UIViewController, presentingViewController presenting: UIViewController!, sourceViewController source: UIViewController) -> UIPresentationController?

    Objective-C

    - (UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source

    Parameters

    presented

    The view controller being presented.

    presenting

    The view controller that is presenting the view controller in the presented parameter. The object in this parameter could be the root view controller of the window, a parent view controller that is marked as defining the current context, or the last view controller that was presented. This view controller may or may not be the same as the one in the source parameter. This parameter may also be nil to indicate that the presenting view controller will be determined later.

    source

    The view controller whose presentViewController:animated:completion: method was called to initiate the presentation process.

    Return Value

    The custom presentation controller for managing the modal presentation.

    Discussion

    When you present a view controller using the UIModalPresentationCustom presentation style, the system calls this method and asks for the presentation controller that manages your custom style. If you implement this method, use it to create and return the custom presentation controller object that you want to use to manage the presentation process.

    If you do not implement this method, or if your implementation of this method returns nil, the system uses a default presentation controller object. The default presentation controller does not add any views or content to the view hierarchy.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.