---
title: "transition(from:to:duration:options:animations:completion:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uiviewcontroller/transition(from:to:duration:options:animations:completion:)"
---

# transition(from:to:duration:options:animations:completion:)

Transitions between two of the view controller’s child view controllers.

## Declaration

```swift
func transition(from fromViewController: UIViewController, to toViewController: UIViewController, duration: TimeInterval, options: UIView.AnimationOptions = [], animations: (() -> Void)?, completion: ((Bool) -> Void)? = nil)
```

## Parameters

- `fromViewController`: A view controller whose view is currently visible in the parent’s view hierarchy.
- `toViewController`: A child view controller whose view is not currently in the view hierarchy.
- `duration`: The total duration of the animations, in seconds. If you pass zero, the changes are made without animating them.
- `options`: A mask of options indicating how you want to perform the animations. For a list of valid constants, see doc://com.apple.uikit/documentation/UIKit/UIView/AnimationOptions.
- `animations`: A block object containing the changes to commit to the views. Here you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value. This parameter must not be NULL.
- `completion`: A block to be called when the animation completes. The block takes the following parameters:

## Discussion

Discussion This method adds the second view controller’s view to the view hierarchy and then performs the animations defined in your animations block. After the animation completes, it removes the first view controller’s view from the view hierarchy. This method is only intended to be called by an implementation of a custom container view controller. If you override this method, you must call super in your implementation.

## See Also

### Managing child view controllers in a custom container

- [children](uikit/uiviewcontroller/children.md)
- [addChild(_:)](uikit/uiviewcontroller/addchild(_:).md)
- [removeFromParent()](uikit/uiviewcontroller/removefromparent().md)
- [shouldAutomaticallyForwardAppearanceMethods](uikit/uiviewcontroller/shouldautomaticallyforwardappearancemethods.md)
- [beginAppearanceTransition(_:animated:)](uikit/uiviewcontroller/beginappearancetransition(_:animated:).md)
- [endAppearanceTransition()](uikit/uiviewcontroller/endappearancetransition().md)
- [hierarchyInconsistencyException](uikit/uiviewcontroller/hierarchyinconsistencyexception.md)
