New TabBarController Transition Animation in iOS 18 and Xcode 16
Apple just launched their new iOS 18, and Mac OS Sequoia. Developers are obligated to update the Xcode to the newest version Xcode 16.0 after updating the newest Mac OS.
After the update, there’s gonna be some little adjustment as usual, that can make your apps not running as you would expect.
The obvious difference when you compile your apps using Xcode 16.0, and you are using UITabbarController is, there’s gonna be a new transition animation when you switch tab, that looks like cross dissolve animation. From what i observe, Apple set this by default when you switch between tabs in UITabbarController.
It is different than the previous Xcode, which by default not giving any animation whatsoever when you switch tab in UITabBarController.
To put in perspective, the new transition animation also applies to default application that apple provided like Music/Apple Music. You can see the new animation in here.
This new animation can lead to unexpected behavior which developers might not like. The animation is like cross dissolve look-alike. Apple might want to make the transition more smooth, but i do prefer to use no animation to make a more snappy impression overall.
For those who want to disable this default animation while using UITabBarController, just simply add this code to your shouldSelectViewController listener/delegate :
Swift:
extension YourTabBarController: UITabBarControllerDelegate {
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
// Disable transition when switching tabs on iOS 18 and Xcode 16
guard let fromView = selectedViewController?.view,
let toView = viewController.view else {
return false
}
if fromView != toView {
UIView.transition(from: fromView,
to: toView,
duration: 0,
options: [.transitionCrossDissolve],
completion: nil)
}
return true
}
}
Objc:
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
// Disable transition when switching tabs on iOS 18 and Xcode 16
UIViewController *fromViewController = tabBarController.selectedViewController;
UIView *fromView = fromViewController.view;
UIView *toView = viewController.view;
if (fromView != toView) {
[UIView transitionFromView:fromView
toView:toView
duration:0
options:UIViewAnimationOptionTransitionCrossDissolve
completion:nil];
}
return true;
}
We use transitionFromView to override default tab switching animation. Also we are still using the options and specify the transition using TransitionCrossDissolve with 0 Duration. We applied this to prevent apple to applied the default transition, some versions of iOS might still try to apply a default transition, which could result in a visible flicker or unexpected behavior. Zero duration was set to make the transition happen instantaneously, appearing as if there’s no transition at all.
And just like that, the default animation is BACK AGAIN!!! No more power point look-alike animation. More snappy, and no unecessary animation. Horayyyy!!!
Thanks for reading, hope this article help!