透明导航栏但保持iOS模糊

时间:2014-09-13 02:06:22

标签: ios objective-c iphone cocoa-touch ios7

在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问题,但他们并没有帮助我。他们回答如何获得completely transparent navbarget a certain colour,当我想要的是清晰/透明,没有任何颜色色调时。

我将如何实现这一目标?感谢您的帮助,非常感谢!

2 个答案:

答案 0 :(得分:0)

让它变得半透明。

将其子类化,并添加代码 -

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

答案 1 :(得分:0)

试试这个,它基于ToolBar的模糊透明度,你也可以为该栏添加一些颜色: 这个解决方案很好,你需要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];
相关问题