Real time blur effect for Navigation Bar

后端 未结 9 2325
不思量自难忘°
不思量自难忘° 2020-11-28 05:21

How to achieve the real time blurring effect for the navigation bar just like the Trailers app in iPhone.

i.e As you scroll the contents should get blurred behind th

9条回答
  •  一向
    一向 (楼主)
    2020-11-28 06:11

    This is neoneye's solution from above, which works perfectly, applied to a UIToolbar.

    extension UIToolbar {
        func toolBarBlurEffect() {
            isTranslucent = true
            setBackgroundImage(UIImage(), forToolbarPosition: .any, barMetrics: .default)
            let statusBarHeight: CGFloat = UIApplication.shared.statusBarFrame.height
            var blurFrame = bounds
            blurFrame.size.height += statusBarHeight
            let blurView  = UIVisualEffectView(effect: UIBlurEffect(style: .dark))
            blurView.isUserInteractionEnabled = false
            blurView.frame = blurFrame
            blurView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
            addSubview(blurView)
            blurView.layer.zPosition = -1
        }
    }
    

    Usage is similar:

    navigationController?.toolbar.toolBarBlurEffect()
    

提交回复
热议问题