Transition Delegate for UITabBarController animation
Asked Answered
O

2

5

I have a custom UIViewControllerAnimationTransition class created already, and need to make this animate a UITabBarController when it switches tabs.

The tabBarController does not use the regular tab bar, though. I have a custom implementation that acts like it, and when a button is pressed, it calls this code:

tabBarController.selectedIndex = index

Currently I have the tabBarController (subclass) as the delegate for its own transitionDelegate. The delegate method animationControllerForPresentedController is never actually called, though.

Is it fine for the tab bar controller to be its own delegate? If so, why is the transition code never actually called?

Okeechobee answered 24/7, 2014 at 1:16 Comment(1)
there's a really good solution here that explains it [enter link description here][1] [1]: https://mcmap.net/q/202566/-iphone-how-to-switch-tabs-with-an-animationJanson
O
14

animationControllerForPresentedController is the wrong approach for the tab bar controller.

In the UITabBarController subclass, adopt the UITabBarControllerDelegate protocol and set it as its own delegate. Then, use tabBarController: animationControllerForTransitionFromViewController: toViewController: to return the custom UIViewControllerAnimatedTransitioning object.

To get a better visualization, look at VCTransitionsLibrary in the TabBarDemo folder.

Okeechobee answered 24/7, 2014 at 16:15 Comment(5)
Shouldn't it be UIViewControllerTransitionDelegate instead of UITabBarControllerDelegate?Domett
No, I mean, shouldn't it be delegate, instead of transitionDelegate! My bad.Domett
@AndréFratelli don't think so. The delegate and the transition delegate do different things. The delegate handles events like when a button is pressed, while the transition delegate handles animations.Okeechobee
Yes, but it's the delegate and not the transition delegate that implements tabBarController:animationControllerForTransitionFromViewController:toViewController:Domett
@AndréFratelli OK I see what you mean. I'm surprised nobody else caught that before :)Okeechobee
E
0

Did you use these delegate methods like this?

@interface BTSlideInteractor : NSObject <UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate>

- (IBAction)showModalButtonWasTouched:(id)sender
{
    BTSlideInteractor *interactor = [[BTSlideInteractor alloc] init];
    interactor.presenting = YES;

    BTModalViewController *modalController = [self.storyboard instantiateViewControllerWithIdentifier:@"ModalViewController"];
    modalController.modalPresentationStyle = UIModalPresentationCustom;
    modalController.transitioningDelegate = interactor;
    [self presentViewController:modalController animated:YES completion:nil];
}

Use this link for Reference: https://github.com/brightec/CustomViewControllerTransition/blob/master/test/BTViewController.m

If you didnt find the solution kindly add your codes.

Etoile answered 24/7, 2014 at 5:11 Comment(1)
Are you saying that the trabsition delegate should be set for the view controllers not the tab bar?Okeechobee

© 2022 - 2024 — McMap. All rights reserved.