问题描述
按照
如何解决?
调试:
打印(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.
这篇关于导航栏的实时模糊效果 - 状态栏无法进入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!