Created
November 14, 2017 10:56
-
-
Save nguyentruongky/1fc3f2ef2dc35a3ef7b2772b458abc57 to your computer and use it in GitHub Desktop.
Fade animation in tab bar controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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