objective-c iOS 7 TabBar 半透明问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20979281/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 21:10:32  来源:igfitidea点击:

iOS 7 TabBar Translucent issue

iphoneobjective-cios7uitabbar

提问by Michael Ortiz

I have an issue, when I set the translucent box off on a TabBar, there is something blocking some of my view.

我有一个问题,当我在 TabBar 上设置半透明框时,有些东西挡住了我的视线。

It looks like it's a sort of extra tab bar or I don't even know. I'm using storyboard.

它看起来像是一种额外的标签栏,或者我什至不知道。我正在使用故事板。

Please see the images attached:

请参阅所附图片:

With Translucent (OFF - NO):

使用半透明(关闭 - 否):

With Translucent (OFF - NO)

半透明 (OFF - NO)

With Translucent (ON or YES):

使用半透明(ON 或 YES):

With Translucent (ON or YES)

半透明(ON 或 YES)

Does anybody know why it looks like this?

有谁知道为什么它看起来像这样?

Thanks

谢谢

PS: Which tabBar do you guys like? Black or this one:

PS:你们喜欢哪个tabBar?黑色或这个:

enter image description here

在此处输入图片说明

回答by nalyd88

This happens in iOS7 when you set tabBar.translucentto NO. iOS is trying to be smart and say "hey the tabbar is not translucent so we better push everything up on top of it". Fix it by setting the extendedLayoutIncludesOpaqueBarsproperty of the view controller inside the navigation controller which is inside the tabbar controller to YES.

当您设置tabBar.translucentNO. iOS 正试图变得聪明并说“嘿,标签栏不是半透明的,所以我们最好将所有东西都推到它上面”。通过将extendedLayoutIncludesOpaqueBars位于标签栏控制器内的导航控制器内的视图控制器的属性设置为 来修复它YES

Example (not actually ran):

示例(未实际运行):

UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.tabBar.barStyle = UIBarStyleBlack;
tabBarController.tabBar.translucent = NO;

UIViewController *viewController = [[UIViewController alloc] init];
viewController.extendedLayoutIncludesOpaqueBars = YES; // <-- This is important!!!!!!

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: viewController];

tabBarController.viewControllers = @[navigationController];

Source: https://web.archive.org/web/20160405135605/https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/AppearanceCustomization.html

来源:https: //web.archive.org/web/20160405135605/https: //developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/AppearanceCustomization.html

And BTW, I like the non-translucent tabbar the best.

顺便说一句,我最喜欢不透明的标签栏。

Edit

编辑

As Andy mentioned below, this flag does not have to be set in code. You can set it in IB if that's what you use.

正如安迪在下面提到的,这个标志不必在代码中设置。如果那是你使用的,你可以在 IB 中设置它。

回答by Ali Riahipour

As mentioned hereyou have to set barTintColor to something you want to change the color.

正如这里提到的您必须将 barTintColor 设置为您想要更改颜色的内容。

These settings automatically apply when you set any style for barStyle or any custom color for barTintColor. If you prefer, you can make the tab bar opaque by setting the translucent property to NO programmatically. In this case, the bar draws an opaque background using black if the tab bar has UIBarStyleBlack style, white if the tab bar has UIBarStyleDefault, or the tab bar's barTintColor if a custom value is defined.

当您为 barStyle 设置任何样式或为 barTintColor 设置任何自定义颜色时,这些设置会自动应用。如果您愿意,可以通过以编程方式将 translucent 属性设置为 NO 来使标签栏不透明。在这种情况下,如果标签栏具有 UIBarStyleBlack 样式,则该栏使用黑色绘制不透明背景,如果标签栏具有 UIBarStyleDefault 则使用白色,或者如果定义了自定义值,则使用标签栏的 barTintColor 绘制不透明背景。

Something that I used for my project

我用于我的项目的东西

self.tabBarController.tabBar.barTintColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0];

self.tabBarController.tabBar.translucent = NO;

回答by Marciano

I have acontroller with TableView and both translucent NavigationBar and translucent TabBar.
In this situation using

viewController.extendedLayoutIncludesOpaqueBars = YES;

causes a problem of both bars overlaping my table view.

It can be managed by setting

viewController.edgesForExtendedLayout = UIRectEdgeBottom;

which results in TableView hiding only behind Tab Bar.

我有一个带有 TableView 和半透明 NavigationBar 和半透明 TabBar 的控制器。
在这种情况下,使用

viewController.extendedLayoutIncludesOpaqueBars = YES;

会导致两个条形重叠我的表格视图的问题。

它可以通过设置

viewController.edgesForExtendedLayout = UIRectEdgeBottom;

导致 TableView 仅隐藏在 Tab Bar 后面来管理。

回答by Caleb

It looks like you've set up the view controller's view so that its bottom is at the same position as the top of the tab bar, when it shouldbe at the bottom of the screen. If you do that, then your content will appear correctly (content visible through the tab bar or not) whether the tab bar is set to translucent or not.

看起来您已经设置了视图控制器的视图,使其底部与选项卡栏的顶部位于同一位置,而此时它应该位于屏幕底部。如果您这样做,那么无论标签栏是否设置为半透明,您的内容都会正确显示(内容是否通过标签栏可见)。

回答by Michael Pirotte

For those who actually wanta translucent Tabbar and a table view (or collection view for me) that can be seen behind, here is my solution for ios 7/8:

对于那些真正想要一个可以在后面看到的半透明 Tabbar 和表视图(或我的集合视图)的人,这是我的 ios 7/8 解决方案:

If you are using constraints, you should add one on the bottom of the table view to the "Bottom Layout Guide" so your tableview stops before the Tabbar. This is an example with Storyboard, but it can be done in code as well.
enter image description here
Then you just need to make sure you can still see the table view behind the Tabbar by settings the "clipsToBounds" property to NO.

如果您正在使用约束,您应该在表格视图底部添加一个到“底部布局指南”,以便您的表格视图在 Tabbar 之前停止。这是 Storyboard 的一个示例,但也可以在代码中完成。
在此处输入图片说明
然后,您只需要通过将“clipsToBounds”属性设置为 NO,确保您仍然可以看到 Tabbar 后面的表格视图。

self.mytableview.clipsToBounds = NO;

This is my solution, hope it helps.

这是我的解决方案,希望它有所帮助。