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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值