如何移除UITabBarController「更多」菜单的默认右滑动画
Hey Andrew, great question—you definitely don’t have to settle for that default slide transition or the laggy back swipe! We can completely remove the transition animations and eliminate that stutter with a few lines of code. Here’s how:
Step 1: Subclass UITabBarController
The key is to intercept the UIMoreNavigationController (the system-managed navigation controller that handles the "More" menu) and override its transition behavior. Create a custom subclass for your tab bar controller:
class CustomTabBarController: UITabBarController, UINavigationControllerDelegate { override func viewDidLoad() { super.viewDidLoad() // Attach ourselves as the delegate for the More menu's navigation controller moreNavigationController.delegate = self } // Disable all transition animations for the More navigation stack func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationController.Operation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { // Returning nil tells the system to skip any animation return nil } // Optional: Prevent interactive swipe gestures (if you want to fully eliminate any transition-related lag) func navigationController(_ navigationController: UINavigationController, interactionControllerFor animationController: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? { return nil } }
Step 2: Use Your Custom Tab Bar Controller
Make sure your app uses this custom subclass instead of the default UITabBarController—either set it in Interface Builder (change the class of your tab bar controller to CustomTabBarController) or initialize it programmatically.
Why This Works
- By setting
moreNavigationController.delegate = self, we take control of how transitions are handled for the "More" menu’s navigation stack. - Returning
nilfromanimationControllerFordisables all push/pop animations entirely, so switching to a tab from the "More" menu (and navigating back) happens instantly with no slide effect. - The optional
interactionControllerFormethod disables the swipe-to-go-back gesture, which can eliminate any remaining lag caused by gesture recognition conflicts with the default animation.
This approach gives you the clean, instant transitions you want without breaking the core "More" menu functionality you already like.
内容的提问来源于stack exchange,提问作者Andrew Lombard

