Created
August 11, 2020 20:05
-
-
Save camiloibarrayepes/0e7a7f73d596e2bd7b648c3490e5939d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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