-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTSBlurEffectView.swift
53 lines (39 loc) · 1.15 KB
/
TSBlurEffectView.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
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// TSBlurEffectView.swift
// MazeLogics
//
// Created by Tallha Sarwar on 20/05/2021.
// Copyright © 2021 Finja Pvt Limited. All rights reserved.
//
import Foundation
class TSBlurEffectView: UIVisualEffectView {
var animator = UIViewPropertyAnimator(duration: 1, curve: .linear)
var intensity = 1.0
override func layoutSubviews() {
super.layoutSubviews()
frame = superview?.bounds ?? CGRect.zero
setupBlur()
}
override func didMoveToSuperview() {
guard let superview = superview else { return }
backgroundColor = .clear
setupBlur()
}
private func setupBlur() {
animator.stopAnimation(true)
effect = nil
animator.addAnimations { [weak self] in
self?.effect = UIBlurEffect(style: .regular)
}
if intensity > 0 && intensity <= 10 {
let value = CGFloat(intensity)/10
animator.fractionComplete = value
}
else {
animator.fractionComplete = 0.05
}
}
deinit {
animator.stopAnimation(true)
}
}