如何使 UINavigationBar 背景透明? [英] How to make UINavigationBar background transparent?

查看:51
本文介绍了如何使 UINavigationBar 背景透明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我已经在

我正在使用(在 viewDidLoadviewWillAppear: 中都试过):

[self.navigationController.navigationBar setBackgroundImage:[UIImage new]forBarMetrics:UIBarMetricsDefault];self.navigationController.navigationBar.shadowImage = [UIImage new];self.navigationController.navigationBar.translucent = YES;self.navigationController.view.backgroundColor = [UIColor clearColor];

我明白了:

灰色状态栏背景,完全白色的导航栏与状态栏不融合,然后视图开始.其他问题答案"中的所有解决方案"对我来说都产生了相同的结果.

我也尝试设置 self.edgesForExtendedLayout = UIRectEdgeNone;self.edgesForExtendedLayout = UIRectEdgeAll; 但这也没有任何影响.

如何让我的导航栏透明而不弄乱一切?

更新: 按照 Warif Akhand Rishi 的回答,我已将 self.navigationController.view.backgroundColor = [UIColor clearColor]; 更改为 self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];,现在我得到了一个灰色的、统一的状态/导航栏,但仍然不透明:

更新 2:我已经连接了视图调试器,灰色背景似乎来自视图层次结构的最深处,并且我的视图内容没有向上扩展.我用最新的代码再次尝试了 self.edgesForExtendedLayout = UIRectEdgeAll; 但仍然无济于事:

解决方案

好的,经过努力,我自己解决了问题.问题不止一个.这不是关于扩展边缘,而是关于行 self.navigationController.view.backgroundColor = [UIColor clearColor]; (必须是 self.navigationController.navigationBar.backgroundColor =[UIColor clearColor]; 正如 Warif Akhand Rishi 建议的那样)以及我的表格视图的剪辑子视图属性.我已经更改了该行并关闭了我的表格视图的剪辑,现在它可以按预期工作了.

First of all, I've seen all the answers at How to make UINavigationBar Transparent in IOS 8? Transparent UINavigationBar and Make UINavigationBar transparent.

They just don't seem to work for me.

My regular view controller (before trying to make the navigation bar transparent) doesn't have any issues:

I'm using (tried both in viewDidLoad and viewWillAppear:):

[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
                                              forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = [UIColor clearColor];

I'm getting this:

Gray status bar background, completely white navigation bar which doesn't blend with the status bar, and then the view starts. All the 'solutions' at the other questions' answers' yield the same result for me.

I've also tried setting self.edgesForExtendedLayout = UIRectEdgeNone; or self.edgesForExtendedLayout = UIRectEdgeAll; but that also didn't have any impact.

How can I make my navigation bar transparent without messing up everything?

UPDATE: Following Warif Akhand Rishi's answer, I've changed self.navigationController.view.backgroundColor = [UIColor clearColor]; to self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];, now I'm getting a gray, unified status/navbar, but still not transparent:

UPDATE 2: I've hooked up the view debugger, and that gray background seems to come from deep down from the roots of view hierarchy, and my view's content is not extending up. I've tried self.edgesForExtendedLayout = UIRectEdgeAll; again with the latest code but still no avail:

解决方案

Okay, after struggling, I've solved the problem on my own. There was more than one problem. It wasn't about the extended edges, it was about the line self.navigationController.view.backgroundColor = [UIColor clearColor]; (which had to be self.navigationController.navigationBar.backgroundColor = [UIColor clearColor]; as Warif Akhand Rishi suggested) and also my table view's clip subviews property. I've changed that line and also turned off clipping of my table view and now it works as expected.

这篇关于如何使 UINavigationBar 背景透明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆