【问题标题】:Blur effect on navigation bar while using a tableviewcontroller使用 tableviewcontroller 时导航栏上的模糊效果
【发布时间】:2016-09-01 16:11:41
【问题描述】:

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?

【问题讨论】:

    标签: ios swift uinavigationbar


    【解决方案1】:

    试一试:

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

    找到它here

    【讨论】:

      猜你喜欢
      • 2015-02-03
      • 2015-09-09
      • 2020-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-06
      • 1970-01-01
      • 2020-08-30
      相关资源
      最近更新 更多