CNLiveConfigManager.swift
2.06 KB
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
//
// CNLiveConfigManager.swift
// metaCode
//
// Created by open on 2023/6/5.
//
import Foundation
class CNLiveConfigManager : NSObject {
static let shared = CNLiveConfigManager()
public var keyboardDisplayHeight : CGFloat = 0
private override init() {
super.init()
NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidShowNotification), name: UIResponder.keyboardDidShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidChangeFrameNotification), name: UIResponder.keyboardDidChangeFrameNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidHideNotification), name: UIResponder.keyboardDidHideNotification, object: nil)
}
deinit {
NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardDidShowNotification, object: nil)
NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardDidChangeFrameNotification, object: nil)
NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardDidHideNotification, object: nil)
}
override class func copy() -> Any {
return self
}
override class func mutableCopy() -> Any {
return self
}
@objc private func keyboardDidShowNotification(notification : Notification) {
let keyboardValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue
CNLiveConfigManager.shared.keyboardDisplayHeight = keyboardValue?.cgRectValue.size.height ?? 0
}
@objc private func keyboardDidChangeFrameNotification(notification : Notification) {
let keyboardValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue
CNLiveConfigManager.shared.keyboardDisplayHeight = keyboardValue?.cgRectValue.size.height ?? 0
}
@objc private func keyboardDidHideNotification(notification : Notification) {
CNLiveConfigManager.shared.keyboardDisplayHeight = 0
}
}