簡體   English   中英

帶有視圖的疊加標簽欄

[英]Overlay tabbar with a view

我在Tab欄中有一個UIViewController 對於Tab欄中的一個VC,我允許界面在設備旋轉時旋轉。 挑戰在於,我想隱藏標簽欄並調整我的視圖。

我做了什么:

1)調用- (void)willAnimateRotation....在我的Tab欄控制器中並將self.tabBar.isHidden設置為true - > Tab欄消失。

2)調用- (void)willAnimateRotation....並將self.mapView.frame設置為最大高度。

但是......我仍然在屏幕底部有一個黑色條紋,與標簽欄的大小完全相同。 有沒有辦法讓標簽欄完全消失?

[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];    
}

這對我有用

- (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;
        }
    }
}

如果要在按下特定的UIViewController時始終隱藏標簽欄,您可以執行以下操作:

self.hidesBottomBarWhenPushed = YES;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM