如何实现类似 iPhone 中的 Trailers 应用程序中导航栏的实时模糊效果。 即当您滚动内容时,导航栏后面的内容应该变得模糊。
请帮我写一些代码。
谢谢!
我想要实现这样的效果:
这是neoneye在上面提供的解决方案,完美地应用于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
}
}
使用方法类似:
navigationController?.toolbar.toolBarBlurEffect()
UIVisualEffectView
"的模糊类。 - Hemang