-2

我有这个 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];

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

4

2 回答 2

2

在你的第一个视图控制器中添加这个

-(void)viewWillAppear:(BOOL)animated{
     self.tabBarController.tabBar.hidden = YES;
}
于 2013-09-02T10:33:07.010 回答
1

如果你想从不同的视图控制器多次显示和隐藏你的标签栏,那么在你的 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];
}
于 2013-09-02T10:41:38.060 回答