Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MihaelIsaev/aefdc18dbe339489498663324d9bb527 to your computer and use it in GitHub Desktop.
Save MihaelIsaev/aefdc18dbe339489498663324d9bb527 to your computer and use it in GitHub Desktop.
UIVisualEffectView subclass that allows to customise effect intensity
import UIKit
class CustomIntensityVisualEffectView: UIVisualEffectView {
/// Create visual effect view with given effect and its intensity
///
/// - Parameters:
/// - effect: visual effect, eg UIBlurEffect(style: .dark)
/// - intensity: custom intensity from 0.0 (no effect) to 1.0 (full effect) using linear scale
init(effect: UIVisualEffect, intensity: CGFloat) {
super.init(effect: nil)
animator = UIViewPropertyAnimator(duration: 1, curve: .linear) { [unowned self] in self.effect = effect }
animator.fractionComplete = intensity
}
required init?(coder aDecoder: NSCoder) {
fatalError()
}
// MARK: Private
private var animator: UIViewPropertyAnimator!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment