5

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

Ashish Kakkad
  • 23,586
  • 12
  • 103
  • 136
Isaac Wasserman
  • 1,461
  • 4
  • 19
  • 39

2 Answers2

1

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?

Sazid Iqabal
  • 409
  • 2
  • 21
  • 1
    This doesn't work when programatically calling .setSelectedIndex, however it does work when tapping tabs on the tab bar controller. Is there any way to improve your answer so that it will work for the method call mentioned? – TheJeff Jul 19 '19 at 15:45
1

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

TheJeff
  • 3,665
  • 34
  • 52