Skip to content

Instantly share code, notes, and snippets.

@erikolsson
Last active April 12, 2019 05:45
Show Gist options
  • Save erikolsson/baf954b0bae7fae629e5c413c26a8b9f to your computer and use it in GitHub Desktop.
Save erikolsson/baf954b0bae7fae629e5c413c26a8b9f to your computer and use it in GitHub Desktop.
class AdjustableVisualEffectView: UIVisualEffectView {
private var animator: UIViewPropertyAnimator!
init(effect: UIVisualEffect?, intensity: CGFloat) {
super.init(effect: nil)
self.animator = UIViewPropertyAnimator(duration: 1, curve: .linear) { [weak self] in
self?.effect = effect
}
self.intensity = intensity
animator.fractionComplete = intensity
}
var intensity: CGFloat = 0 {
didSet {
animator.fractionComplete = intensity
}
}
required init?(coder aDecoder: NSCoder) {
fatalError()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment