【问题标题】:Transparent Navigation Bar but Keep iOS Blur透明导航栏但保持 iOS 模糊
【发布时间】:2014-11-07 06:35:49
【问题描述】:

在 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,而我只想让它清晰/透明,没有任何颜色

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

【问题讨论】:

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


    【解决方案1】:

    让它变成半透明的。

    对其进行子类化,并添加代码 -

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

    【讨论】:

      【解决方案2】:

      试试这个,它基于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];
      

      【讨论】:

        猜你喜欢
        • 2016-03-10
        • 2014-09-11
        • 1970-01-01
        • 2020-09-19
        • 2018-03-05
        • 2016-12-20
        • 2014-11-08
        • 2021-11-05
        • 2018-09-21
        相关资源
        最近更新 更多