隐藏iPhone上的标签栏

时间:2013-09-02 10:29:40

标签: iphone ios objective-c uitabbar

我有这个UITabBar,在AppDelegate.m中使用此代码创建:

UITabBarController *tbc = [[UITabBarController alloc] init];

BarsViewController *bvc = [[BarsViewController alloc] init];
StopwatchViewController *svc = [[StopwatchViewController alloc] init];
TimerViewController *tvc = [[TimerViewController alloc] init];

[bvc.tabBarItem setTitle:@"Clock"];
[svc.tabBarItem setTitle:@"Stopwatch"];
[tvc.tabBarItem setTitle:@"Timer"];

[tbc setViewControllers:[NSArray arrayWithObjects:svc, bvc, tvc, nil] animated:YES];

[tbc setSelectedIndex:1];

我希望标签栏完全隐藏,而不是推高屏幕上的任何图层。有没有办法做到这一点?

2 个答案:

答案 0 :(得分:2)

在你的第一个viewcontroller中添加这个

-(void)viewWillAppear:(BOOL)animated{
     self.tabBarController.tabBar.hidden = YES;
}

答案 1 :(得分:1)

如果您想从不同的视图控制器多次显示和隐藏您的tabbar,请在appDelegate.m文件中实现以下代码

- (void) hideTabBar:(UITabBarController *) tabbarcontroller
{
int height = 480;
if (([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight)
    || ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft))
{
    height = 320;
}
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
for(UIView *view in tabbarcontroller.view.subviews)
{
    if([view isKindOfClass:[UITabBar class]])
    {
        [view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];
    }
    else {
        [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, height)];
    }
}
[UIView commitAnimations];
}

-(void) showTabBar:(UITabBarController *) tabbarcontroller
{
int height = 431;
if (([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight)
    || ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft))
{
    height = 271;
}
[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, height, view.frame.size.width, view.frame.size.height)];
    }
    else {
        [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, height)];
    }
}
[UIView commitAnimations];
}
相关问题