ios - 在 iOS7 中隐藏 tabBar 显示黑条

标签 ios objective-c swift xcode

我正在使用此代码隐藏 TabBar:

self.tabBarController.tabBar.hidden=YES;

我将 tabBarController 隐藏在我的项目中。但它在 Ios7 的 View 底部显示黑条。当我返回相同的 View 时,它看起来不错。任何帮助将不胜感激。

最佳答案

注意:它仅适用于 iOS6 和 7。

在 iOS 7 中,要扩展可点击区域并在隐藏的 UITabBar 的位置隐藏黑条,您应该为 UIViewController 启用“扩展边缘 - 在不透明条下”选项。

Extend Edges - Under Opaque Bars option

或者您可以通过编程方式设置此属性:

[self setExtendedLayoutIncludesOpaqueBars:YES]

这是隐藏或移动 iOS 6/7 的 TabBar 的代码示例:

UITabBarController *bar = [self tabBarController];
if ([self respondsToSelector:@selector(setExtendedLayoutIncludesOpaqueBars:)]) {
    //iOS 7 - hide by property
    NSLog(@"iOS 7");
    [self setExtendedLayoutIncludesOpaqueBars:YES];
    bar.tabBar.hidden = YES;
} else {
    //iOS 6 - move TabBar off screen
    NSLog(@"iOS 6");
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    float height = screenRect.size.height;
    [self moveTabBarToPosition:height];
}

//Moving the tab bar and its subviews offscreen so that top is at position y
-(void)moveTabBarToPosition:(int)y {

    self.tabBarController.tabBar.frame = CGRectMake(self.tabBarController.tabBar.frame.origin.x, y, self.tabBarController.tabBar.frame.size.width, self.tabBarController.tabBar.frame.size.height);

    for(UIView *view in self.tabBarController.view.subviews) {
        if ([view isKindOfClass:[UITabBar class]]) {
            [view setFrame:CGRectMake(view.frame.origin.x, y, view.frame.size.width, view.frame.size.height)];
        } else {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, y)];
            view.backgroundColor = [UIColor blackColor];
        }
    }
}

将标签栏移出屏幕的功能来自 this post .

关于ios - 在 iOS7 中隐藏 tabBar 显示黑条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19225450/

相关文章:

objective-c - NSKeyedArchiver 为 UIView 的 subview 返回 nil

ios - 如何在 NSString 中正确编码 Unicode 字符?

php - Objective-C POST请求未发送数据

iphone - 导航栏隐藏在 iPhone sdk 中的弹出 View Controller 上

Swift - 检测 UIView 的触摸坐标

ios - menuController Action 的 tableView 设置编辑不起作用

ios - AIR iOS 应用程序中的文本 URL 不可选择

从 "Accu-Chek Aviva Connect"BG 仪表收集数据的 iOS 应用程序。 (低功耗蓝牙)

ios - 如何快速设置选项卡栏 Controller 的默认选项卡

swift - 在 DatePicker-swift 中限制小时和分钟?