导航栏的实时模糊效果 - 状态栏无法进入 [英] Real time blur effect for Navigation Bar - Status bar not getting in

查看:30
本文介绍了导航栏的实时模糊效果 - 状态栏无法进入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照

如何解决?

<小时>

调试:

 打印(self.navigationController?.navigationBar.bounds)//返回 (0.0, 0.0, 320.0, 44.0)打印(UIApplication.sharedApplication().statusBarFrame)//返回 (0.0, 0.0, 320.0, 20.0)

解决方案

部分原因是您将视觉效果视图的框架设置为导航栏的边界.您在屏幕截图中看到的导航栏的边界.因此,您可以通过为视觉效果视图提供不同的框架来进行补偿,即将其原点向上移动 20 点并增加其高度.

我有点不清楚,为什么不让导航栏变成半透明.导航栏半透明模糊效果,支持.您正在做的事情 - 向导航栏添加子视图 - 不是.

Followed this question to get real time blur effect in Navigation Bar:

func addBlurEffect() {
var bounds = self.navigationController?.navigationBar.bounds as CGRect!
var visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light)) as UIVisualEffectView
visualEffectView.frame = bounds
visualEffectView.autoresizingMask = .FlexibleHeight | .FlexibleWidth
self.navigationController?.navigationBar.addSubview(visualEffectView)
}

But the status bar remains translucent:

How to fix it?


Debugging:

    print(self.navigationController?.navigationBar.bounds)
    // Returns (0.0, 0.0, 320.0, 44.0)

    print(UIApplication.sharedApplication().statusBarFrame)
    // Returns (0.0, 0.0, 320.0, 20.0)

解决方案

It's partly because you set the visual effect view's frame to the navigation bar's bounds. What you see in the screen shot are the navigation bar's bounds. So, you might be able to compensate by giving your visual effect view a different frame, i.e. move its origin up 20 points and increase its height.

It's a little unclear to me, though, why you don't just make the navigation bar translucent. Navigation bar translucency is the blur effect, and it is supported. What you're doing — adding a subview to the navigation bar — is not.

这篇关于导航栏的实时模糊效果 - 状态栏无法进入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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