Skip to content

Instantly share code, notes, and snippets.

@nguyentruongky
Created November 14, 2017 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nguyentruongky/1fc3f2ef2dc35a3ef7b2772b458abc57 to your computer and use it in GitHub Desktop.
Save nguyentruongky/1fc3f2ef2dc35a3ef7b2772b458abc57 to your computer and use it in GitHub Desktop.
Fade animation in tab bar controller
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
animateFading(fromController: selectedViewController, toController: viewController)
return true
}
func animateFading(fromController: UIViewController?, toController: UIViewController?) {
if fromController == nil || toController == fromController { return }
guard let selectView = (selectedViewController as? UINavigationController)?.viewControllers.first?.view,
let newView = (toController as? UINavigationController)?.viewControllers.first?.view else { return }
let fromView = selectView
let toView = newView
UIView.transition(from: fromView, to: toView, duration: 0.35, options: [.transitionCrossDissolve], completion: nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment