Skip to content

Instantly share code, notes, and snippets.

@lanserxt
Last active December 28, 2018 12:54
Show Gist options
  • Save lanserxt/ad0e4eb4c8aedda8f228730f4625ec00 to your computer and use it in GitHub Desktop.
Save lanserxt/ad0e4eb4c8aedda8f228730f4625ec00 to your computer and use it in GitHub Desktop.
Blur animator
fileprivate var propertyAnimator: UIViewPropertyAnimator!
fileprivate var blurEffectView: UIVisualEffectView!
fileprivate var backGradientView: UIView!
func addWorkoutBlur() {
if !UIAccessibilityIsReduceTransparencyEnabled() {
if blurEffectView != nil {
blurEffectView.removeFromSuperview()
}
if backGradientView != nil {
backGradientView.removeFromSuperview()
}
if propertyAnimator != nil {
propertyAnimator.stopAnimation(true)
}
backGradientView = UIView(frame: self.bounds)
backGradientView.backgroundColor = UIColor.init(hexString: "#dae1e3")?.withAlphaComponent(0.7)
self.cornerView.addSubview(backGradientView)
let blurEffect = UIBlurEffect(style: .regular)
blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.bounds
self.foreImageView.addSubview(blurEffectView)
propertyAnimator = UIViewPropertyAnimator.init(duration: 3.0, curve: .linear) {[weak self] in
self?.blurEffectView.effect = nil
}
propertyAnimator.fractionComplete = 0.7
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment