1

我有一个UIViewController内部的标签栏。对于Tab栏中的一个VC,我允许接口在设备旋转时旋转。挑战在于,我想隐藏Tab栏并调整视图的大小。覆盖tabbar与视图

我做了什么:

1)在我的标签栏控制器称为- (void)willAnimateRotation....并设置self.tabBar.isHidden为true - >标签栏消失了。

2)称为- (void)willAnimateRotation....并将self.mapView.frame设置为最大高度。

但是...我仍然在屏幕底部有一个黑色的条纹,标签栏的确切尺寸。有没有办法让标签栏完全消失?

回答

1
[self hideTabBar:self.tabBarController]; 


- (void) hideTabBar:(UITabBarController *) tabbarcontroller { 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
    for(UIView *view in tabbarcontroller.view.subviews) 
    { 
     if([view isKindOfClass:[UITabBar class]]) 
     { 
      [view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)]; 
     } 
     else 
     { 
      [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)]; 
     } 

    } 
    [UIView commitAnimations];  
} 
+0

伟大的作品,编辑功能也反向工作。非常感谢! – Michal

+0

欢迎您:) – Rajneesh071

1

这为我工作

- (void)viewDidLoad { 
    [super viewDidLoad];  
    previousRect = self.view.frame;  
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return YES; 
} 

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; 
{ 
    if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {    
     [self.navigationController setNavigationBarHidden:TRUE animated:FALSE]; 
     [[UIApplication sharedApplication] setStatusBarHidden:TRUE animated:FALSE]; 
    } 
    else 
    { 
     [self.navigationController setNavigationBarHidden:FALSE animated:FALSE]; 
     [[UIApplication sharedApplication] setStatusBarHidden:FALSE animated:FALSE]; 
    } 
} 

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    UIInterfaceOrientation toOrientation = self.interfaceOrientation; 

    if (self.tabBarController.view.subviews.count >= 2) 
    { 
     UIView *transView = [self.tabBarController.view.subviews objectAtIndex:0]; 
     UIView *tabBar = [self.tabBarController.view.subviews objectAtIndex:1]; 

     if(toOrientation == UIInterfaceOrientationLandscapeLeft || toOrientation == UIInterfaceOrientationLandscapeRight) {          
       transView.frame = CGRectMake(0, 0, 480, 320); 
       tabBar.hidden = TRUE; 
     } 
     else 
     {        
       transView.frame = previousRect;   
       tabBar.hidden = FALSE; 
     } 
    } 
} 
1

如果你想永远隐藏标签栏当一个特定的UIViewController推,你可以这样做:

self.hidesBottomBarWhenPushed = YES;