Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I stop the tab bar spoiling my flip transition?

Tags:

iphone

ios4

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.

like image 276
Tommy Herbert Avatar asked Nov 14 '22 01:11

Tommy Herbert


1 Answers

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!

like image 128
zorz Avatar answered Jan 02 '23 20:01

zorz