I was searching the web for answers on how to give the CurlUp / CrossDissolve / FlipFromRight / FlipFromLeft / CurlDown / FlipFromTop / FlipFromBottom transition effect for the UITabBar Tab Switch.
I found this answer, but it has a bug or a black screen when you tap on the same tab twice, i.e., the destination and current tab are the same.
So I solve this issue with my logic and additional if and else statement.
So here is the final answer without any bugs.
Step 01:
Add these two classes as Super Class to your UITabBarViewController
UITabBarController, UITabBarControllerDelegate
Step 02:
Now add the following code to your viewDidLoad Function in your UITabBarViewController
self.delegate = self
So your viewDidLoad Function will look something like this:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.delegate = self;
}
Step 03:
Now add the following Function to your UITabBarViewController file.
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
let fromView = selectedViewController?.view
let toView = viewController.view
if fromView !== toView {
UIView.transition(from: fromView!, to: toView!, duration: 0.5, options: [.transitionCrossDissolve], completion: nil)
} else {
}
return true
}
Hopefully, if you have done everything right, you should see the Tab Bar transition on the Tab Bar switch.
Hope it helps,
Thanks & Regards
Mandar Apte
Thank you for the guide. I’m new to iOS programming and I put the delegate in all my viewcontroller files and they conflicted with each other.
Just add delegate only to UITabBarViewController file & not at any other place.