Isaac Wasserman
Isaac Wasserman

Reputation: 1541

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?

Upvotes: 5

Views: 5094

Answers (2)

TheJeff
TheJeff

Reputation: 4101

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

Upvotes: 1

Sazid Iqabal
Sazid Iqabal

Reputation: 429

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?

Upvotes: 1

Related Questions