UITabBarController with hidden UITabBar

...

None of these solutions I've been able to find (here, or elsewhere) to hide a UITabBar as part of a UITabBarController worked well for me. In general, the solutions I found always had some problem when changing orientation, or were tied to a fixed size.

After grappling with this problem and experimenting with various solutions I eventually figured out the following fairly simple solution, which is working very well in testing so far. Easy to implement, and doesn't seem to cause any other problems. In particular, it plays very nicely with interface orientation changes.

I resolved the problem using the following method in a subclass of UITabBarController. In theory, you could also put this in the delegate to avoid having to subclass. I would only require some minor changes (eg, replace 'self' with the UITabBarController object). I call this method from the delegate's tabBarController:shouldSelectViewController: method, and tell it to hide the tab bar for one of the items (the one I want to be full screen), and to not hide for any of the other items.

Is this safe to use? Are there likely to be any problems with this that I've not come across yet?

The only problem I can think of is that if UITabBarController's view ever gets more than two subviews (it depends on it having two subviews: the tab bar and the content view).
@implementation CustomTabBarController

- (void)makeTabBarHidden:(BOOL)hide
{
	if ( [self.view.subviews count] < 2 )
		return;
	
	UIView *contentView;
	
	if ( [[self.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )
		contentView = [self.view.subviews objectAtIndex:1];
	else
		contentView = [self.view.subviews objectAtIndex:0];
	
	if ( hide )
	{
		contentView.frame = self.view.bounds;		
	}
	else
	{
		contentView.frame = CGRectMake(self.view.bounds.origin.x,
			self.view.bounds.origin.y,
			self.view.bounds.size.width,
			self.view.bounds.size.height - self.tabBar.frame.size.height);
	}
	
	self.tabBar.hidden = hide;
}

@end

转帖:http://www.iphonedevsdk.com/forum/iphone-sdk-development/4091-uitabbarcontroller-hidden-uitabbar.html

你可能感兴趣的:(UITabBarController with hidden UITabBar)