隱藏TabBar的一些方法小結(適用與各類狀況)
- 在項目中常常遇到隱藏tabBar,實力不少種方法,能夠解決不一樣狀況下問題
-
- 使用中涉及到view的層次關係,下面的使用方法 一、2不作說明;在使用三、4方法時注意要在tabBar所在的rootView中調用實現(必要時使用委託,已達到所須要的目的)
- 舉例:A(rootView 是tabBarCtroller);B(A的subView);C(B經過pushViewController)
- 若是想要C出現的時候將tabView隱藏(且C是全屏的,能展開到tabbar存在的位置),B顯示的時候babView在顯示出來
- 此狀況明顯一、2方法不能實現了,要用三、4的方法來實現;
- 實現方式:B在pushViewController的時候調用其委託函數(即B消失C出現時tabbar隱藏)
- if([delegaterespondsToSelector:@selector(hidenTabbar:)])
- {
- [delegatehidenTabbar:YES];
- }
- 在A中實現B的委託代碼就是三、4;
- 一樣在B的viewWillAppear中也調用其委託:NO;(B顯示時tabbar出現)
- -(void)viewWillAppear:(BOOL)animated
- {
- if([delegate respondsToSelector:@selector(hidenTabbar:)])
- {
- [delegatehidenTabbar:NO];
- }
- }
-
- 1:
- WebViewController *webVc = [[WebViewController alloc] init];
- webVc.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:webVc animated:YES];
- webVc.hidesBottomBarWhenPushed = NO;
- [webVc release];
-
- 2.系統方法 self.hidesBottomBarWhenPushed = YES;
-
-
- 3:自定義tabBar時候,由tabBarController管理的
- - (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, iphone5?568:480, view.frame.size.width, view.frame.size.height)];
- } else {
- [view setFrame:CGRectMake(view.frame.origin.x, iphone5?568-49:480-49, 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, iphone5?568:480)];
- } else {
- [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, iphone5?568-49:480-49)];
- }
- }
- }
-
- [UIView commitAnimations];
- }
-
- for (UIView *subView in self.view.subviews) {
- if ([subView isKindOfClass:NSClassFromString(@"UITransitionView")]) {
-
-
-
- CGRect frame = subView.frame;
- frame.size.height = 480;
- subView.frame = frame;
- }
- }
-
- 4:相似方法3
- - (void)makeTabBarHidden:(BOOL)hide
- {
- if ( [self.tabBarController.view.subviews count] < 2 )
- {
- return;
- }
- UIView *contentView;
-
- if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )
- {
- contentView = [self.tabBarController.view.subviews objectAtIndex:1];
- }
- else
- {
- contentView = [self.tabBarController.view.subviews objectAtIndex:0];
- }
-
- if ( hide )
- {
- contentView.frame = self.tabBarController.view.bounds;
- }
- else
- {
- contentView.frame = CGRectMake(self.tabBarController.view.bounds.origin.x,
- self.tabBarController.view.bounds.origin.y,
- self.tabBarController.view.bounds.size.width,
- self.tabBarController.view.bounds.size.height - self.tabBarController.tabBar.frame.size.height);
- }
-
- self.tabBarController.tabBar.hidden = hide;
- }
歡迎關注本站公眾號,獲取更多信息