Created
December 29, 2018 14:48
-
-
Save vialyx/b70d25d722c52db71ccb6fe17e8de797 to your computer and use it in GitHub Desktop.
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
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