You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.6 KiB
92 lines
2.6 KiB
//
|
|
// VisualEffectView.swift
|
|
// VisualEffectView
|
|
//
|
|
// Created by Lasha Efremidze on 5/26/16.
|
|
// Copyright © 2016 Lasha Efremidze. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
/// VisualEffectView is a dynamic background blur view.
|
|
open class VisualEffectView: UIVisualEffectView {
|
|
|
|
/// Returns the instance of UIBlurEffect.
|
|
private let blurEffect = (NSClassFromString("_UICustomBlurEffect") as! UIBlurEffect.Type).init()
|
|
|
|
/**
|
|
Tint color.
|
|
|
|
The default value is nil.
|
|
*/
|
|
open var colorTint: UIColor? {
|
|
get { return _value(forKey: "colorTint") as? UIColor }
|
|
set { _setValue(newValue, forKey: "colorTint") }
|
|
}
|
|
|
|
/**
|
|
Tint color alpha.
|
|
|
|
The default value is 0.0.
|
|
*/
|
|
open var colorTintAlpha: CGFloat {
|
|
get { return _value(forKey: "colorTintAlpha") as! CGFloat }
|
|
set { _setValue(newValue, forKey: "colorTintAlpha") }
|
|
}
|
|
|
|
/**
|
|
Blur radius.
|
|
|
|
The default value is 0.0.
|
|
*/
|
|
open var blurRadius: CGFloat {
|
|
get { return _value(forKey: "blurRadius") as! CGFloat }
|
|
set { _setValue(newValue, forKey: "blurRadius") }
|
|
}
|
|
|
|
/**
|
|
Scale factor.
|
|
|
|
The scale factor determines how content in the view is mapped from the logical coordinate space (measured in points) to the device coordinate space (measured in pixels).
|
|
|
|
The default value is 1.0.
|
|
*/
|
|
open var scale: CGFloat {
|
|
get { return _value(forKey: "scale") as! CGFloat }
|
|
set { _setValue(newValue, forKey: "scale") }
|
|
}
|
|
|
|
// MARK: - Initialization
|
|
|
|
public override init(effect: UIVisualEffect?) {
|
|
super.init(effect: effect)
|
|
|
|
commonInit()
|
|
}
|
|
|
|
required public init?(coder aDecoder: NSCoder) {
|
|
super.init(coder: aDecoder)
|
|
|
|
commonInit()
|
|
}
|
|
|
|
private func commonInit() {
|
|
scale = 1
|
|
}
|
|
|
|
// MARK: - Helpers
|
|
|
|
/// Returns the value for the key on the blurEffect.
|
|
private func _value(forKey key: String) -> Any? {
|
|
return blurEffect.value(forKeyPath: key)
|
|
}
|
|
|
|
/// Sets the value for the key on the blurEffect.
|
|
private func _setValue(_ value: Any?, forKey key: String) {
|
|
blurEffect.setValue(value, forKeyPath: key)
|
|
self.effect = blurEffect
|
|
}
|
|
|
|
}
|
|
|
|
// ["grayscaleTintLevel", "grayscaleTintAlpha", "lightenGrayscaleWithSourceOver", "colorTint", "colorTintAlpha", "colorBurnTintLevel", "colorBurnTintAlpha", "darkeningTintAlpha", "darkeningTintHue", "darkeningTintSaturation", "darkenWithSourceOver", "blurRadius", "saturationDeltaFactor", "scale", "zoom"]
|