使用tableviewcontroller时模糊导航栏上的效果

时间:2016-09-01 16:11:42

标签: 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?

1 个答案:

答案 0 :(得分:0)

试一试:

apple = search_for_string(['a', 'b', 'c'], 'b')
apple = search_for_string([], 'b')

找到它here