Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animated transition on TabBarController?.selectedIndex change? (Swift)

Is it possible to create a custom tabBarController class in swift to animate programmatic and interactive transitions between tabs?

like image 784
Isaac Wasserman Avatar asked Oct 31 '22 04:10

Isaac Wasserman


2 Answers

You can try this for transition animation on tabbar selecetion

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 }

for reference use this link

How to animate Tab bar tab switch with a CrossDissolve slide transition?

like image 141
Sazid Iqabal Avatar answered Nov 11 '22 13:11

Sazid Iqabal


I just figured this out, and posted an answer on another thread (link below). It adds a method:

tabBarController.setSelectedWithIndex(1)

to get this done with an animation.

I hope it works for you!

Answer: https://stackoverflow.com/a/57116930/1993937

like image 23
TheJeff Avatar answered Nov 11 '22 14:11

TheJeff