@@ -20,12 +20,6 @@ import UIKit
20
20
21
21
// MARK: - CustomKeyboard
22
22
public class CustomKeyboard : UIView , KeyboardLayoutDelegate {
23
- public var uppercaseToggledLayout : KeyboardLayout !
24
- public var uppercaseLayout : KeyboardLayout !
25
- public var lowercaseLayout : KeyboardLayout !
26
- public var numbersLayout : KeyboardLayout !
27
- public var symbolsLayout : KeyboardLayout !
28
-
29
23
public var shiftToggleInterval : NSTimeInterval = 0.5
30
24
private var shiftToggleTimer : NSTimer ?
31
25
private var shiftCanBeToggled : Bool = false
@@ -36,6 +30,51 @@ public class CustomKeyboard: UIView, KeyboardLayoutDelegate {
36
30
private var backspaceDeleteTimer : NSTimer ?
37
31
private var backspaceAutoDeleteModeTimer : NSTimer ?
38
32
33
+ public var uppercaseToggledLayout : KeyboardLayout ! {
34
+ didSet {
35
+ guard currentLayout != nil && oldValue != nil else { return }
36
+ if currentLayout == oldValue {
37
+ currentLayout = uppercaseToggledLayout
38
+ }
39
+ }
40
+ }
41
+
42
+ public var uppercaseLayout : KeyboardLayout ! {
43
+ didSet {
44
+ guard currentLayout != nil && oldValue != nil else { return }
45
+ if currentLayout == oldValue {
46
+ currentLayout = uppercaseLayout
47
+ }
48
+ }
49
+ }
50
+
51
+ public var lowercaseLayout : KeyboardLayout ! {
52
+ didSet {
53
+ guard currentLayout != nil && oldValue != nil else { return }
54
+ if currentLayout == oldValue {
55
+ currentLayout = lowercaseLayout
56
+ }
57
+ }
58
+ }
59
+
60
+ public var numbersLayout : KeyboardLayout ! {
61
+ didSet {
62
+ guard currentLayout != nil && oldValue != nil else { return }
63
+ if currentLayout == oldValue {
64
+ currentLayout = numbersLayout
65
+ }
66
+ }
67
+ }
68
+
69
+ public var symbolsLayout : KeyboardLayout ! {
70
+ didSet {
71
+ guard currentLayout != nil && oldValue != nil else { return }
72
+ if currentLayout == oldValue {
73
+ currentLayout = symbolsLayout
74
+ }
75
+ }
76
+ }
77
+
39
78
private var lastLetterLayout : KeyboardLayout ?
40
79
private( set) var currentLayout : KeyboardLayout ! {
41
80
didSet {
@@ -65,16 +104,12 @@ public class CustomKeyboard: UIView, KeyboardLayoutDelegate {
65
104
}
66
105
67
106
private func defaultInit( ) {
68
- uppercaseToggledLayout = CustomKeyboardLayout . UppercaseToggled. keyboardLayout
69
- uppercaseLayout = CustomKeyboardLayout . Uppercase. keyboardLayout
70
- lowercaseLayout = CustomKeyboardLayout . Lowercase. keyboardLayout
71
- numbersLayout = CustomKeyboardLayout . Numbers. keyboardLayout
72
- symbolsLayout = CustomKeyboardLayout . Symbols. keyboardLayout
73
-
107
+ reload ( )
74
108
currentLayout = uppercaseLayout
75
109
addSubview ( currentLayout)
76
110
}
77
111
112
+ // MARK: Layout
78
113
public override func layoutSubviews( ) {
79
114
super. layoutSubviews ( )
80
115
currentLayout? . frame = CGRect (
@@ -84,6 +119,15 @@ public class CustomKeyboard: UIView, KeyboardLayoutDelegate {
84
119
height: frame. size. height)
85
120
}
86
121
122
+ // MARK: Reload
123
+ public func reload( ) {
124
+ uppercaseToggledLayout = CustomKeyboardLayout . UppercaseToggled. keyboardLayout
125
+ uppercaseLayout = CustomKeyboardLayout . Uppercase. keyboardLayout
126
+ lowercaseLayout = CustomKeyboardLayout . Lowercase. keyboardLayout
127
+ numbersLayout = CustomKeyboardLayout . Numbers. keyboardLayout
128
+ symbolsLayout = CustomKeyboardLayout . Symbols. keyboardLayout
129
+ }
130
+
87
131
// MARK: Backspace Auto Delete
88
132
private func startBackspaceAutoDeleteModeTimer( ) {
89
133
backspaceAutoDeleteModeTimer = NSTimer . scheduledTimerWithTimeInterval (
0 commit comments