Skip to content

Instantly share code, notes, and snippets.

@camiloibarrayepes
Created August 11, 2020 20:05
Show Gist options
  • Select an option

  • Save camiloibarrayepes/0e7a7f73d596e2bd7b648c3490e5939d to your computer and use it in GitHub Desktop.

Select an option

Save camiloibarrayepes/0e7a7f73d596e2bd7b648c3490e5939d to your computer and use it in GitHub Desktop.
// Set blur gaussian effect to a UIView
let visualEffectView = UIVisualEffectView(effect: nil)
let totalContainerView = UIView()
let animator = UIViewPropertyAnimator(duration: 0.5, curve: .linear)
self.view.setBlurEffectGeneral(mainView: self.view,
animator: animator,
totalContainer: totalContainerView,
visualEffect: visualEffectView)
extension UIView {
func setBlurEffectGeneral(mainView: UIView,
animator: UIViewPropertyAnimator,
totalContainer: UIView,
visualEffect: UIVisualEffectView,
effectLevel: Double? = 0.09) {
let widthView = mainView.frame.size.width
let heightView = mainView.frame.size.height
totalContainer.frame = CGRect(x: 0, y: 0, width: widthView, height: heightView)
mainView.insertSubview(totalContainer, at: 0)
totalContainer.addSubview(visualEffect)
visualEffect.fillSuperview()
animator.addAnimations {
visualEffect.effect = UIBlurEffect(style: .regular)
}
animator.fractionComplete = CGFloat(effectLevel ?? 0.09)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment