@@ -44,6 +44,18 @@ open class KeyboardTrackingView: UIView {
44
44
/// The margin to maintain between the keyboard and the top of the view.
45
45
@IBInspectable open var topMargin : CGFloat = 0
46
46
47
+ /// Subclasses can override this to do something before the change.
48
+ open func willChange(
49
+ change: KeyboardTrackingView . Change ,
50
+ userInfo: [ AnyHashable : Any ]
51
+ ) { }
52
+
53
+ /// Subclasses can override this to do something after the change.
54
+ open func didChange(
55
+ change: KeyboardTrackingView . Change ,
56
+ userInfo: [ AnyHashable : Any ]
57
+ ) { }
58
+
47
59
override public init ( frame: CGRect ) {
48
60
super. init ( frame: frame)
49
61
postInit ( )
@@ -101,11 +113,12 @@ open class KeyboardTrackingView: UIView {
101
113
guard !( isPaused || isAutomaticallyPaused) ,
102
114
let userInfo = ( notification as NSNotification ) . userInfo,
103
115
let value = userInfo [ UIResponder . keyboardFrameEndUserInfoKey] as? NSValue else { return }
116
+ willChange ( change: change, userInfo: userInfo)
117
+ delegate? . keyboardTrackingViewWillChange ( change: change, userInfo: userInfo)
104
118
let keyboardRect = value. cgRectValue
105
119
let thisRect = convert ( bounds, to: nil )
106
120
let newHeight = max ( 0 , thisRect. maxY - keyboardRect. minY) + topMargin
107
121
guard heightConstraint. constant != newHeight else { return }
108
- delegate? . keyboardTrackingViewWillChange ( change: change, userInfo: userInfo)
109
122
animateKeyboardChange ( change: change, height: newHeight, userInfo: userInfo)
110
123
}
111
124
@@ -115,6 +128,7 @@ open class KeyboardTrackingView: UIView {
115
128
let curveNumber = userInfo [ UIResponder . keyboardAnimationCurveUserInfoKey] as? NSNumber {
116
129
CATransaction . begin ( )
117
130
CATransaction . setCompletionBlock {
131
+ self . didChange ( change: change, userInfo: userInfo)
118
132
self . delegate? . keyboardTrackingViewDidChange ( change: change, userInfo: userInfo)
119
133
}
120
134
UIView . beginAnimations ( nil , context: nil )
0 commit comments