.hidesBottomBarWhenPushed = NO; doesn't work because the view isn't getting pushed. I want the t开发者_如何学编程abBar to be hidden on the first screen and able to show it again a few screens later.
How can I do this?
Subclass your UITabBarController and add a function like this
- (void) hideTabBar:(BOOL)hide animated:(BOOL)animated {
if (tabBarHidden == hide) { return; }
if (animated) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5];
}
for(UIView *view in self.view.subviews) {
if([view isKindOfClass:[UITabBar class]]) {
if (!hide) {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y-49, view.frame.size.width, view.frame.size.height)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y+49, view.frame.size.width, view.frame.size.height)];
}
} else {
if (!hide) {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height-49)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height+49)];
}
}
}
if (animated) { [UIView commitAnimations]; }
tabBarHidden = hide;
}
Whilst your at it, add a function like this to allow the tab bar to rotate
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return allowRotate;
}
This is going to be difficult because tabbars are designed to be the top level of the application's UI. The documentation is very clear on this. As such, they don't play well in a controller hierarchy in which they are not on top.
Really the only way to accomplish what you want is programmatically create the tabbar when you want it to appear. However, I can't say that will produce reliable code. The tabbar will be fighting you all the way.
You really should rethink your UI design. Using the tabbar in a non-standard way will confuse your users. Since the standard is to have tabbars at top level of the UI, users will believe they are at the top level when they see a tabbar. They will get disoriented. You really need to stick to standard usage so that your app agrees with the interface grammar that the users have learned.
See the iPhone Human Interface Guidelines.
精彩评论