How can I stop the tab bar spoiling my flip transition?
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 hidesBottomBarWh开发者_开发问答enPushed
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.
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!
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.
精彩评论