我正在使用此代码隐藏 TabBar:
self.tabBarController.tabBar.hidden=YES;
我将 tabBarController 隐藏在我的项目中。但它在 Ios7 的 View 底部显示黑条。当我返回相同的 View 时,它看起来不错。任何帮助将不胜感激。
最佳答案
注意:它仅适用于 iOS6 和 7。
在 iOS 7 中,要扩展可点击区域并在隐藏的 UITabBar 的位置隐藏黑条,您应该为 UIViewController 启用“扩展边缘 - 在不透明条下”选项。
或者您可以通过编程方式设置此属性:
[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/