-2

AppDelegate.m のこのコードで作成されたこの UITabBar があります。

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

異なるView Controllerから複数回タブバーを表示および非表示にしたい場合は、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 に答える