Forked from darrarski/CustomIntensityVisualEffectView.swift
Created
September 29, 2019 17:02
-
-
Save MihaelIsaev/aefdc18dbe339489498663324d9bb527 to your computer and use it in GitHub Desktop.
UIVisualEffectView subclass that allows to customise effect intensity
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
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