5

I've created an iOS tab bar app with a navigation controller in one of the tabs. It uses a flip animation when it pushes or pops views from the stack (I found out how to do that here).

It's looking great, except for a problem with the tab bar. The view at the root of the stack shows the tab bar, but for the next one I've set hidesBottomBarWhenPushed to YES. Pushing works great; the issue is popping back to the root view controller. My view flips from the left, except the tab bar, which slides in.

Here's my code for popping the view controller:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
                       forView:self.navigationController.view
                         cache:NO];
[UIView setAnimationDuration:flipDuration];
[self.navigationController popViewControllerAnimated:NO];
[UIView commitAnimations];

The weird thing is that if I comment out all except the fourth statement, the tab bar behaves itself - it doesn't slide in, it just appears instantly with the rest. For some reason, adding the transition has allowed the tab bar to say to itself, 'Well, everyone else is animated. Why shouldn't I be animated? But no poncy flipping for me. I think I'll stick to a slide.'

What can I do? Ideally, I'd like the tab bar to flip in with the rest, but I'd also be happy with it fading in afterwards.

Community
  • 1
  • 1
Tommy Herbert
  • 20,407
  • 14
  • 52
  • 57

2 Answers2

1

I got it! After looking at this, and one other answer to a different question, I found the solution.

In the controller you want to push the transition from, use this code:

[UIView transitionWithView:[[self navigationController] view]
                  duration:0.3
                   options:UIViewAnimationOptionTransitionFlipFromRight
                animations:^{
                    [[self navigationController] pushViewController:theView animated:NO];
                } completion:NULL];

In your view you want to transition back, use this code:

[UIView transitionWithView:[[self navigationController] view]
                  duration:0.3
                   options:UIViewAnimationOptionTransitionFlipFromLeft
                animations:^{
                    [[self navigationController] popViewControllerAnimated:NO];
                } completion:NULL];

This keeps the transition from mucking with the tabBar. Give it a shot!

zorz
  • 75
  • 8
0

is it not just as simple as creating a reference to the tabBarObject and then adding that to the animation also, or does that not work either.

That way you can animate it either the same as your view, or differently.

theiOSDude
  • 1,480
  • 2
  • 21
  • 36
  • Thanks for your answer. I think that didn't work, but I'll check as soon as I get back from a trip I'm taking. – Tommy Herbert Apr 21 '11 at 08:58
  • Tried self.navigationController.tabBarController.tabBar.hidden = YES when pushing the view controller instead of setting hidesBottomBarWhenPushed to YES. It vanished before the animation began, even though the new line was between beginAnimations and commitAnimations. I guess that's because the tab bar fits into the hierarchy too high up to be affected by the view animation. – Tommy Herbert May 04 '11 at 01:01
  • this could be true, let me know how you get on. sorry not much more help – theiOSDude May 04 '11 at 07:59