pulitr
pulitr

Reputation: 69

Segue transition from top to bottom in Swift 3

I need help with custom segue transition from top to bottom. Its easy transition but I don't know how to do it. Is it done in a storyboard or must I do it in code? If it must do programmatically how I do it?

Upvotes: 0

Views: 1047

Answers (1)

matt
matt

Reputation: 535616

You are trying to write a custom transition animation for a push segue. So this is what you are going to do:

  • Set a delegate for your navigation controller.

  • In the delegate, implement func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? to return an object implementing UIViewControllerAnimatedTransitioning (this is often self in real life)

  • In that object, implement func transitionDuration(using ctx: UIViewControllerContextTransitioning?) -> TimeInterval and func animateTransition(using ctx: UIViewControllerContextTransitioning).

  • In animateTransition, get the info from the context (ctx). Put the to view into the containerView and animate it to its finalFrame. In your case, you'll start with the view above the final frame and animate it downwards, as you've specified. When you are all done (i.e. in the animation's completion handler), be sure to call completeTransition on the context.

Upvotes: 2

Related Questions