UITabBarController的活用(根據場景隱藏顯示TabBar)

UITabBarController的活用,UITabBarController+UINavigationController的架構中會用到。

1.隱藏TabBar:

[cpp] view plain copy
  1. - (void)hideTabBar {  
  2.     if (self.tabBarController.tabBar.hidden == YES) {  
  3.         return;  
  4.     }  
  5.     UIView *contentView;  
  6.     if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )  
  7.         contentView = [self.tabBarController.view.subviews objectAtIndex:1];  
  8.     else  
  9.         contentView = [self.tabBarController.view.subviews objectAtIndex:0];  
  10.     contentView.frame = CGRectMake(contentView.bounds.origin.x,  contentView.bounds.origin.y,  contentView.bounds.size.width, contentView.bounds.size.height + self.tabBarController.tabBar.frame.size.height);          
  11.     self.tabBarController.tabBar.hidden = YES;  
  12.       
  13. }  
2.顯示TabBar:

[cpp] view plain copy
  1. - (void)showTabBar  
  2.   
  3. {  
  4.     if (self.tabBarController.tabBar.hidden == NO)  
  5.     {  
  6.         return;  
  7.     }  
  8.     UIView *contentView;  
  9.     if ([[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]])  
  10.           
  11.         contentView = [self.tabBarController.view.subviews objectAtIndex:1];  
  12.   
  13.     else  
  14.           
  15.         contentView = [self.tabBarController.view.subviews objectAtIndex:0];        
  16.     contentView.frame = CGRectMake(contentView.bounds.origin.x, contentView.bounds.origin.y,  contentView.bounds.size.width, contentView.bounds.size.height - self.tabBarController.tabBar.frame.size.height);  
  17.     self.tabBarController.tabBar.hidden = NO;  
  18.       
  19. }  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章