Skip to content

Instantly share code, notes, and snippets.

@vialyx
Created December 29, 2018 14:48
Show Gist options
  • Save vialyx/b70d25d722c52db71ccb6fe17e8de797 to your computer and use it in GitHub Desktop.
Save vialyx/b70d25d722c52db71ccb6fe17e8de797 to your computer and use it in GitHub Desktop.
import UIKit
class AnimatedTabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
delegate = self
}
}
// MARK: - UITabBarControllerDelegate
extension AnimatedTabBarController: UITabBarControllerDelegate {
/*
Called to allow the delegate to return a UIViewControllerAnimatedTransitioning delegate object for use during a noninteractive tab bar view controller transition.
ref: https://developer.apple.com/documentation/uikit/uitabbarcontrollerdelegate/1621167-tabbarcontroller
*/
func tabBarController(_ tabBarController: UITabBarController, animationControllerForTransitionFrom fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return TabBarAnimatedTransitioning()
}
}
/*
UIViewControllerAnimatedTransitioning
A set of methods for implementing the animations for a custom view controller transition.
ref: https://developer.apple.com/documentation/uikit/uiviewcontrolleranimatedtransitioning
*/
final class TabBarAnimatedTransitioning: NSObject, UIViewControllerAnimatedTransitioning {
/*
Tells your animator object to perform the transition animations.
*/
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard let destination = transitionContext.view(forKey: UITransitionContextViewKey.to) else { return }
destination.alpha = 0.0
destination.transform = .init(scaleX: 1.5, y: 1.5)
transitionContext.containerView.addSubview(destination)
UIView.animate(withDuration: transitionDuration(using: transitionContext), animations: {
destination.alpha = 1.0
destination.transform = .identity
}, completion: { transitionContext.completeTransition($0) })
}
/*
Asks your animator object for the duration (in seconds) of the transition animation.
*/
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.25
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment