-
Notifications
You must be signed in to change notification settings - Fork 18
/
APCustomBlurView.swift
40 lines (32 loc) · 1.19 KB
/
APCustomBlurView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// APCustomBlurView.swift
// Created by Collin Hundley on 1/15/16.
//
import UIKit
public class APCustomBlurView: UIVisualEffectView {
private let blurEffect: UIBlurEffect
public var blurRadius: CGFloat {
return blurEffect.valueForKeyPath("blurRadius") as! CGFloat
}
public convenience init() {
self.init(withRadius: 0)
}
public init(withRadius radius: CGFloat) {
let customBlurClass: AnyObject.Type = NSClassFromString("_UICustomBlurEffect")!
let customBlurObject: NSObject.Type = customBlurClass as! NSObject.Type
self.blurEffect = customBlurObject.init() as! UIBlurEffect
self.blurEffect.setValue(1.0, forKeyPath: "scale")
self.blurEffect.setValue(radius, forKeyPath: "blurRadius")
super.init(effect: radius == 0 ? nil : self.blurEffect)
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
public func setBlurRadius(radius: CGFloat) {
guard radius != blurRadius else {
return
}
blurEffect.setValue(radius, forKeyPath: "blurRadius")
self.effect = blurEffect
}
}