Zigglzworth Zigglzworth - 3 months ago 41x
iOS Question

iOS / Objective c - UITabBarControllerDelegate - Custom tab animation delegates not called

I am trying to create a custom tabbar animation when a user taps on a tab bar button.

I have implemented a UITabBarController subclass that implements UITabBarControllerDelegate

here is the .m

#import "MYCustomTabBarControler.h"

@interface MYCustomTabBarControler ()


@implementation MYCustomTabBarControler

- (void)viewDidLoad {
[super viewDidLoad];

self.delegate = self; // I set the delegate as self


#pragma mark - UITabBarControllerDelegate

- (BOOL)tabBarController:(UITabBarController *)tabBarController
shouldSelectViewController:(UIViewController *)viewController {

//This is called so I know the delegate is working
NSLog(@"The tabBarController delegate is set and working");
return YES;

//This delegate method is never called
- (id<UIViewControllerAnimatedTransitioning>)tabBarController:(UITabBarController *)tabBarController
UIViewControllerAnimatedTransitioning:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC {

MYBarTransition *animator = [MYBarTransition new];
return animator;


//This delegate method is never called
- (id<UIViewControllerInteractiveTransitioning>)tabBarController:(UITabBarController *)tabBarController
interactionControllerForAnimationController:(id<UIViewControllerAnimatedTransitioning>)animationController {

MYBarTransition *animator = [MYBarTransition new];
return animator;

For some reason the delegate methods responsible for transitioning are NOT called. I have read the docs and can't see any reason they would not be called.

I have set my delegate correctly and confirmed it is
working by implementing the shouldSelectViewController method

What am I missing here?


I think you are using the wrong delegate method for what you are trying to accomplish. Try using:

- (nullable id <UIViewControllerAnimatedTransitioning>)tabBarController:(UITabBarController *)tabBarController
            animationControllerForTransitionFromViewController:(UIViewController *)fromVC
                                              toViewController:(UIViewController *)toVC;

This will be called when the user taps on a different tab.