I've got a UITabBarControllerDelegate set to itself for a UITabBarController. I just want to animate the transition for the UITabBarController child view controllers.
I'm using these methods from UITabBarControllerDelegate and UIViewControllerAnimatedTransitioning:
- (id<UIViewControllerAnimatedTransitioning>)tabBarController:(UITabBarController *)tabBarController animationControllerForTransitionFromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC
{
return self;
}
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView *container = [transitionContext containerView];
[container addSubview:toViewController.view];
[container addSubview:fromViewController.view];
CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height;
if ([[toViewController valueForKey:@"title"] isEqualToString:@"viewControllerTitle"]) {
[container bringSubviewToFront:toViewController.view];
[fromViewController.view setFrame:CGRectMake(0, 0, 320, screenHeight)];
[toViewController.view setFrame:CGRectMake(320, 0, 320, screenHeight)];
[UIView animateWithDuration:0.3 animations:^{
[toViewController.view setFrame:CGRectMake(0, 0, 320, screenHeight)];
}
completion:^(BOOL finished){
[transitionContext completeTransition:finished];
}];
}
}
Every lines of code above are being hit, but the result is just one black screen behind the UITabBar at the bottom, and if I remove the UITabBarControllerDelegate method to not call the transitioning context code, everything works fine.
I'm using a similar transitioning animation code for another part of my app that's just called from a UIViewController.transitioningDelegate instead of a UITabBarController.delegate and it works fine, so I think something is different about how UITabBarControllerDelegate handles transitions.
Can someone see why it gives me that black screen?
Thanks in advance!