iOS Developer Library

Developer

UIKit Framework Reference UIViewControllerContextTransitioning Protocol Reference

Options
Deployment Target:

On This Page
Language:

UIViewControllerContextTransitioning

Inheritance


Not Applicable

Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 7.0 and later.

The UIViewControllerContextTransitioning protocol’s methods provide contextual information for transition animations between view controllers. Do not adopt this protocol in your own classes, nor should you directly create objects that adopt this protocol. During a transition, the animator objects involved in that transition receive a fully configured context object from UIKit. Custom animator objects—objects that adopt the UIViewControllerAnimatorTransitioning or UIViewControllerInteractiveTransitioning protocol—should simply retrieve the information they need from the provided object.

A context object encapsulates information about the views and view controllers involved in the transition. It also contains details about the how to execute the transition. For interactive transitions, the interactive animator object uses the methods of this protocol to report the animation’s progress. When the animation starts, the interactive animator object must save a pointer to the context object. Based on user interactions, the animator object then calls the updateInteractiveTransition:, finishInteractiveTransition, or cancelInteractiveTransition methods to report the progress toward completing the animation. Those methods send that information to UIKit so that it can drive the timing of the animations.

  • The view that acts as the superview for the views involved in the transition. (required)

    Declaration

    Swift

    func containerView() -> UIView

    Objective-C

    - (UIView *)containerView

    Return Value

    The view that contains both views involved in the transition.

    Discussion

    The container view acts as the superview of all other views (including those of the presenting and presented view controllers) during the animation sequence. UIKit sets this view for you and automatically adds the view of the presenting view controller to it. The animator object is responsible for adding the view of the presented view controller, and the animator object or presentation controller must use this view as the container for all other views involved in the transition.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Returns a view controller involved in the transition. (required)

    Declaration

    Swift

    func viewControllerForKey(_ key: String) -> UIViewController?

    Objective-C

    - (UIViewController *)viewControllerForKey:(NSString *)key

    Parameters

    key

    The key identifying the view controller you want. For a list of possible keys, see View Controller Transition Keys.

    Return Value

    The view controller object for the specified key or nil if the view controller could not be found.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Returns the specified view involved in the transition. (required)

    Declaration

    Swift

    func viewForKey(_ key: String) -> UIView?

    Objective-C

    - (UIView *)viewForKey:(NSString *)key

    Parameters

    key

    The key identifying the view you want. For a list of possible keys, see View Transition Keys.

    Return Value

    The view object for the specified key or nil if the view could not be found.

    Discussion

    The view returned by this method may or may not be the root view of the corresponding view controller. A situation where the views may not be the same is when a system-provided presentation controller installs another view underneath the presented view controller’s view.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • Returns the starting frame rectangle for the specified view controller’s view. (required)

    Declaration

    Swift

    func initialFrameForViewController(_ vc: UIViewController) -> CGRect

    Objective-C

    - (CGRect)initialFrameForViewController:(UIViewController *)vc

    Parameters

    vc

    The view controller whose frame rectangle you want.

    Return Value

    The frame rectangle for the view or CGRectZero if the frame rectangle is not known or the view is not visible.

    Discussion

    The rectangle returned by this method represents the size of the corresponding view at the beginning of the transition. For the view controller that is already onscreen, this rectangle typically matches the frame rectangle of the container view. For the view controller being presented, the value returned by this method is typically CGRectZero because the view is not yet on screen.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Returns the ending frame rectangle for the specified view controller’s view. (required)

    Declaration

    Swift

    func finalFrameForViewController(_ vc: UIViewController) -> CGRect

    Objective-C

    - (CGRect)finalFrameForViewController:(UIViewController *)vc

    Parameters

    vc

    The view controller whose frame rectangle you want.

    Return Value

    The frame rectangle for the view or CGRectZero if the frame rectangle is not known or the view is not visible.

    Discussion

    The rectangle returned by this method represents the size of the corresponding view at the end of the transition. For the view being covered during the presentation, the value returned by this method might be CGRectZero but it might also be a valid frame rectangle.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Returns a Boolean value indicating, in the case of a modal presentation style, whether the transition should be animated. (required)

    Declaration

    Swift

    func isAnimated() -> Bool

    Objective-C

    - (BOOL)isAnimated

    Return Value

    Always returns YEStrue for modal presentations styles other than the UIModalPresentationCustom style. For the UIModalPresentationCustom style, returns YEStrue if the transition should be animated or NOfalse if it should not.

    Discussion

    Call this method to determine whether a custom transition should be animated into place. If this method returns NOfalse, insert the final views into the container view without animating the change.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Returns a Boolean value indicating whether the transition is interactive. (required)

    Declaration

    Swift

    func isInteractive() -> Bool

    Objective-C

    - (BOOL)isInteractive

    Return Value

    YEStrue if the transition is interactive or NOfalse if it is not.

    Discussion

    A transition is interactive only if the view controller’s delegate provides a corresponding interactive animator object.

    Interactive transitions are drive by user-generated events. One common scenario is to use a gesture recognizer to report on the current progress of the animation. The gesture recognizer calls methods of this context object that indicate the completion percentage of the transition or indicate that the transition was canceled or completed by the user.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Returns the presentation style for the view controller transition. (required)

    Declaration

    Swift

    func presentationStyle() -> UIModalPresentationStyle

    Objective-C

    - (UIModalPresentationStyle)presentationStyle

    Return Value

    The presentation style to use when presenting the final view controller.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Notifies the system that the transition animation is done. (required)

    Declaration

    Swift

    func completeTransition(_ didComplete: Bool)

    Objective-C

    - (void)completeTransition:(BOOL)didComplete

    Parameters

    didComplete

    YEStrue if the transition to the presented view controller completed successfully or NOfalse if the original view controller is still being displayed.

    Discussion

    You must call this method after your animations have completed to notify the system that the transition animation is done. The parameter you pass must indicate whether the animations completed successfully. For interactive animations, you must call this method in addition to the finishInteractiveTransition or cancelInteractiveTransition method. The best place to call this method is in the completion block of your animations.

    The default implementation of this method calls the animator object’s animationEnded: method to give it a chance to perform any last minute cleanup.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Updates the completion percentage of the transition. (required)

    Declaration

    Swift

    func updateInteractiveTransition(_ percentComplete: CGFloat)

    Objective-C

    - (void)updateInteractiveTransition:(CGFloat)percentComplete

    Discussion

    While tracking user events, gesture recognizers or your interactive animator objects should call this method regularly to update the progress toward completing the transition. If, during tracking, the interactions cross a threshold that you consider signifies the completion or cancellation of the transition, stop tracking events and call the finishInteractiveTransition or cancelInteractiveTransition method.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Notifies the system that user interactions signaled the completion of the transition. (required)

    Declaration

    Swift

    func finishInteractiveTransition()

    Objective-C

    - (void)finishInteractiveTransition

    Discussion

    While tracking user interactions, gesture recognizers or your interactive animator object should call this method when the interactions suggest that the transition is now complete. For example, if the user swipes a finger, and the touch events indicate that the swipe distance crossed the threshold needed to complete the gesture, call this method when the corresponding touch events end to let the system know that it can now complete the transition.

    Always follow calls to this method with a call to the completeTransition: method to finalize the transition.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Notifies the system that user interactions canceled the transition. (required)

    Declaration

    Swift

    func cancelInteractiveTransition()

    Objective-C

    - (void)cancelInteractiveTransition

    Discussion

    While tracking user interactions, gesture recognizers or your interactive animator object should call this method when interactions suggest that the user wants to cancel or abort the view controller transition. For example, if the user reverses the swipe direction and touch events end, suggesting that the user decided against the transition, you would call this method.

    Always follow calls to this method with a call to the completeTransition: method to finalize the transition.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Returns a Boolean value indicating whether the transition was canceled. (required)

    Declaration

    Swift

    func transitionWasCancelled() -> Bool

    Objective-C

    - (BOOL)transitionWasCancelled

    Return Value

    YEStrue if the transition was canceled or NOfalse if it is ongoing or finished normally.

    Discussion

    You can call this method from your animator object to determine whether the transition has been canceled. Calling the cancelInteractiveTransition method causes this method to return YEStrue.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Returns a transform indicating the amount of rotation being applied during the transition. (required)

    Declaration

    Swift

    func targetTransform() -> CGAffineTransform

    Objective-C

    - (CGAffineTransform)targetTransform

    Return Value

    An affine transform indicating the amount of rotation being applied to the interface. This transform is the identity transform when no rotation is applied; otherwise, it is a transform that applies a 90 degree, -90 degree, or 180 degree rotation.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • The keys you use to identify the view controllers involved in a transition.

    Declaration

    Swift

    let UITransitionContextFromViewControllerKey: String let UITransitionContextToViewControllerKey: String

    Objective-C

    NSString *const UITransitionContextFromViewControllerKey; NSString *const UITransitionContextToViewControllerKey;

    Constants

    • UITransitionContextFromViewControllerKey

      UITransitionContextFromViewControllerKey

      Identifies the view controller that is visible at the beginning of the transition (and at the end of a canceled transition). This view controller is typically the one presenting the "to” view controller or is the one being replaced by the "to” view controller.

      Available in iOS 7.0 and later.

    • UITransitionContextToViewControllerKey

      UITransitionContextToViewControllerKey

      Identifies the view controller that is visible at the end of a completed transition. This view controller is the one being presented.

      Available in iOS 7.0 and later.

  • The keys you use to identify the views involved in a transition.

    Declaration

    Swift

    let UITransitionContextFromViewKey: String let UITransitionContextToViewKey: String

    Objective-C

    NSString *const UITransitionContextFromViewKey; NSString *const UITransitionContextToViewKey;

    Constants

    • UITransitionContextFromViewKey

      UITransitionContextFromViewKey

      Identifies the view that is shown at the beginning of the transition (and at the end of a canceled transition). This view is typically the presenting view controller’s view.

      Available in iOS 8.0 and later.

    • UITransitionContextToViewKey

      UITransitionContextToViewKey

      Identifies the view that is shown at the end of a completed transition. This view is typically the presented view controller’s view but may also be an ancestor of that view.

      Available in iOS 8.0 and later.