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;