Skip to content

Instantly share code, notes, and snippets.

@andr3a88
Created November 7, 2018 11:17
Show Gist options
  • Save andr3a88/393e1fe3bbee43aaf5e676ed8a2d8b95 to your computer and use it in GitHub Desktop.
Save andr3a88/393e1fe3bbee43aaf5e676ed8a2d8b95 to your computer and use it in GitHub Desktop.
Extension for UINavigationController for custom transitions
extension UINavigationController {
/// Push the view controller with present animation
///
/// - Parameters:
/// - viewController: The view controller
/// - animationDuration: The animation duration (default 0.25)
func pushPresentViewController(viewController: UIViewController, duration: CFTimeInterval = 0.25) {
let transition = CATransition()
transition.duration = duration
transition.type = .moveIn
transition.subtype = .fromTop
self.view.layer.add(transition, forKey: kCATransition)
self.pushViewController(viewController, animated: false)
}
/// Pop the view controller with dismiss animation
///
/// - Parameters:
/// - animationDuration: The animation duration (default 0.25)
func popDismissViewController(duration: CFTimeInterval = 0.25) {
let transition = CATransition()
transition.duration = duration
transition.type = .reveal
transition.subtype = .fromBottom
self.view.layer.add(transition, forKey: kCATransition)
self.popViewController(animated: false)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment