我对UITabBarController有问题.在我的应用程序中,我想隐藏它,但不使用hidesBottomBarWhenPushed,因为我不想在按下它时隐藏它.例如,我想在应用程序中按下隐藏按钮时隐藏它.

我在谷歌上看了很多文章,但我找不到如何做到这一点.

推荐答案

我正在从我的工作代码中粘贴这个.您可以调用这些方法来隐藏和显示选项卡栏控制器.只需将tabbarController实例传递给这些函数即可.

// Method call
[self hideTabBar:self.tabBarController];   

// Method implementations
- (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)showTabBar:(UITabBarController *) tabbarcontroller
{       
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    for(UIView *view in tabbarcontroller.view.subviews)
    {
        NSLog(@"%@", view);

        if([view isKindOfClass:[UITabBar class]])
        {
            [view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];

        } 
        else 
        {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
        }
    }

    [UIView commitAnimations]; 
}

Ios相关问答推荐

在选项卡内列出导航内视图断开导航标题的动画

AVFoundation Camera推出变焦SWIFT

iOS 17-在Xcode 15中添加导航控制器时,导航栏不会立即显示

如何删除NavigationView中的默认透明标头?

将 Riverpod 从 StateNotifier 修复为 NotifierProvider 以及应用程序生命周期监控

不使用故事板创建 iMessage 应用程序

如何解决错误 HE0004:无法在 Visual Studio 2022 中加载框架ContentDeliveryServices

从视图模型中更新 EnvironmentObject

将值传递给导航链接视图中的文本框

@Environment 的存在会导致列表在滚动时不断重建其内容

在 Swift 中合并子数组

在 tableview 中下载图像缩略图时如何提高滚动性能

为什么我的应用在 Testflight 中没有下载 dSYM 按钮?

何时需要将应用程序源包含在测试目标中?

在 iOS 编程中使用 Storyboard 代替 xib 文件有什么好处?

从 NSData 或 UIImage 中查找图像类型

使用未知类型创建图像格式是一个错误与 UIImagePickerController

应用程序不包含正确的测试版权利

正确使用 Alamofire 的 URLRequestConvertible

UITableView:从空白部分隐藏标题