iPhone中如何在打开一个新view时隐藏全局的TabBar?
参考资料:http://www.cocoachina.com/bbs/simple/?t25042.html
问题实质无非是要把View Tree里的各个组件的大小进行动态调整.
首先在AppDelegate中我有一个UITabBarController, 比如叫 FrameViewController
然后我要push一个叫做 UserDetails 的普通View,并且希望隐藏下面的TabBar
使用setHidden,hidesBottomBarWhenPushed神马的终究不给力,因为即使把TabBar隐藏了,内部的ViewController所占的空间依然没有改变,因此下面会留下一片空白.
归根结底还要自己调整尺寸.
在AppDelegate中定义这儿一个全局函数即可
- (void) hideTabBar:(BOOL) hidden{ [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0]; for(UIView *view in self.tabBarController.view.subviews) { if([view isKindOfClass:[UITabBar class]]) { if (hidden) { [view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)]; } else { [view setFrame:CGRectMake(view.frame.origin.x, 480-44, view.frame.size.width, view.frame.size.height)]; } } else { if (hidden) { [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)]; } else { [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480-44)]; } } } [UIView commitAnimations]; }
然后在 UserDetail 的 viewWillAppear和viewWillDisappear中调用即可