ios - 使用 tableviewcontroller 时对导航栏的模糊效果

标签 ios swift uinavigationbar

Real time blur effect for Navigation Bar

尝试了上面帖子中提到的解决方案,

AppDelegate.swift

// Sets background to a blank/empty image
        UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarMetrics: .Default)
        // Sets shadow (line below the bar) to a blank image
        UINavigationBar.appearance().shadowImage = UIImage()
        // Sets the translucent background color
        UINavigationBar.appearance().backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0)
        // Set translucent. (Default value is already true, so this can be removed if desired.)
        UINavigationBar.appearance().translucent = true

RootVC.swift

func addBlurEffect() {
        // Add blur view
        let bounds = self.navigationController?.navigationBar.bounds as CGRect!
        let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light))
        visualEffectView.frame = bounds
        visualEffectView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
        self.navigationController?.navigationBar.addSubview(visualEffectView)
        self.navigationController?.navigationBar.sendSubviewToBack(visualEffectView)

        // Here you can add visual effects to any UIView control.
        // Replace custom view with navigation bar in above code to add effects to custom view.
    }

viewDidLoad中使用了self.addBlurEffect

问题,状态栏仍然没有模糊,模糊效果仅限于RootVC.swift。

如何将其扩展到所有子 VC?

最佳答案

试一试:

bounds.offsetInPlace(dx: 0.0, dy: -20.0)
bounds.size.height = bounds.height + 20.0

找到了 here

关于ios - 使用 tableviewcontroller 时对导航栏的模糊效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39276341/

相关文章:

iOS 运动检测 : Motion Detection Sensitivity Levels

ios - "Cannot connect to iTunes Store"应用内购买

json - Swift//将一个String Json文件转换为枚举大小写

path - 如何使用 Swift 的文件路径 API 获取文档目录并创建文件名

ios - Locale 可以通过货币代码识别国家吗?

ios - 替换后退按钮但保持滑动以返回

ios - 使用滑动手势识别器从一个 View Controller 滑动到另一个

ios - 临时应用程序在启动时挂起, "has active assertions but is being debugged"

swift - 创建自定义导航栏的更好方法

ios - rightBarButtonItem,leftBarButtonItem 问题