繁体   English   中英

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

[英]Transparent Navigation Bar but Keep iOS Blur

在iOS 7中,导航栏对在下面滚动的内容具有模糊效果。 我希望我的导航栏是透明的,可以这样实现:

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

但我也希望内容模糊。 我没有运气就尝试了以下方法:

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

而是,这会使导航栏使内容视图模糊,但为黑色。 如果删除setBarTintColor ,则导航栏会模糊内容,但它是白色的。 我尝试了其他各种组合,但导航栏是白色或黑色。

我看了几个SO问题,但它们对我没有帮助。 他们回答如何获得完全透明的导航栏获得某种颜色 ,而我想要的是它是透明/透明的, 而没有任何颜色

我将如何实现? 感谢您的帮助,不胜感激!

使它透明。

子类化,并添加代码-

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

尝试此操作,它基于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