I'm trying to change the tab bar in my app programmatically with an animation.
In my tab bar delegate class, I currently have this, which I obtained from this thread.
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
guard let fromView = selectedViewController?.view, let toView = viewController.view else {
return false
}
UIView.transition(from: fromView, to: toView, duration: 0.3, options: [.transitionCrossDissolve], completion: nil)
return true
}
The above animates tab bar changes when the user taps, but does not work for when the tab bar is changed programmatically, like in this case:
// code in another class
self.tabBarController?.selectedIndex = 2 // does not animate
I've read this thread that poses a similar question, but it's written in objective-c and from 4 years ago.
Is there any method that could animate programmatic tab bar changes?