简体   繁体   English

透明的导航栏,但保持iOS模糊

[英]Transparent Navigation Bar but Keep iOS Blur

In iOS 7 navigation bars have a blur effect for content that is scrolled underneath. 在iOS 7中,导航栏对在下面滚动的内容具有模糊效果。 I would like my navigation bar to be transparent, which is achieved like so: 我希望我的导航栏是透明的,可以这样实现:

[[UINavigationBar appearance] setBarStyle:UIBarStyleDefault];
[[UINavigationBar appearance] setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[UIImage new]];
[[UINavigationBar appearance] setBackgroundColor:[UIColor  clearColor]];

But I would like the content to blur as well. 但我也希望内容模糊。 I tried the following with no luck: 我没有运气就尝试了以下方法:

[[UINavigationBar appearance] setBarTintColor:[UIColor clearColor]];
        [[UINavigationBar appearance] setBarStyle:UIBarStyleDefault];
        [[UINavigationBar appearance] setShadowImage:[UIImage new]];
        [[UINavigationBar appearance] setBackgroundColor:[UIColor  clearColor]];

Instead, this makes the navigation bar blur the content view but is black. 而是,这会使导航栏使内容视图模糊,但为黑色。 If I remove the setBarTintColor , the navbar blurs the content but it's white. 如果删除setBarTintColor ,则导航栏会模糊内容,但它是白色的。 I've tried various other combinations but the navbar is either white or black. 我尝试了其他各种组合,但导航栏是白色或黑色。

I've looked at several SO questions but they don't help me. 我看了几个SO问题,但它们对我没有帮助。 They answer how to get a completely transparent navbar or get a certain colour , when all I want is it to be clear/transparent, without any kind of colour tint . 他们回答如何获得完全透明的导航栏获得某种颜色 ,而我想要的是它是透明/透明的, 而没有任何颜色

How would I achieve this? 我将如何实现? Thanks for any help, it's appreciated! 感谢您的帮助,不胜感激!

Make it translucent. 使它透明。

Subclass it, and add the code - 子类化,并添加代码-

- (id)initWithRootViewController:(UIViewController *)rootViewController
{
    if (self = [super initWithRootViewController:rootViewController]) {
        self.navigationBar.translucent = YES;
    }
    return self;
}

Try this, it is based on the blurred transparency of ToolBar, you can also add some color to that bar: This solution is good of you need iOS7 support 尝试此操作,它基于ToolBar的模糊透明度,您也可以为该Bar添加一些颜色:此解决方案很好,因为您需要iOS7支持

[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];
UIToolbar* blurredView = [[UIToolbar alloc] initWithFrame:self.navigationController.navigationBar.bounds];
[blurredView setBarStyle:UIBarStyleBlack];
[self.navigationController.navigationBar insertSubview:blurredView atIndex:0];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM