1
1
import UIKit
2
2
3
3
4
+ #if swift(>=4.2)
5
+ public typealias AnimationOptions = UIView . AnimationOptions
6
+ #else
7
+ public typealias AnimationOptions = UIViewAnimationOptions
8
+ #endif
9
+
10
+
4
11
//MARK: - MAIN
5
12
@nonobjc
6
13
public extension Keyboard {
@@ -14,13 +21,13 @@ public extension Keyboard {
14
21
/// The keyboard's transition duration.
15
22
public let transitionDuration : Double
16
23
/// The keyboard's transition animation options.
17
- public let transitionAnimationOptions : UIViewAnimationOptions
24
+ public let transitionAnimationOptions : AnimationOptions
18
25
19
26
//MARK: - Setup
20
27
private init ( initialTransitionRect: CGRect ,
21
28
finalTransitionRect: CGRect ,
22
29
transitionDuration: Double ,
23
- transitionAnimationOptions: UIViewAnimationOptions )
30
+ transitionAnimationOptions: AnimationOptions )
24
31
{
25
32
self . initialTransitionRect = initialTransitionRect
26
33
self . finalTransitionRect = finalTransitionRect
@@ -30,12 +37,20 @@ public extension Keyboard {
30
37
31
38
fileprivate init ? ( userInfo: [ AnyHashable : Any ] )
32
39
{
40
+ #if swift(>=4.2)
41
+ guard let initialRect = ( userInfo [ UIResponder . keyboardFrameBeginUserInfoKey] as? NSValue ) ? . cgRectValue,
42
+ let finalRect = ( userInfo [ UIResponder . keyboardFrameEndUserInfoKey] as? NSValue ) ? . cgRectValue,
43
+ let duration = ( userInfo [ UIResponder . keyboardAnimationDurationUserInfoKey] as? NSNumber ) ? . doubleValue,
44
+ let options = ( userInfo [ UIResponder . keyboardAnimationCurveUserInfoKey] as? NSNumber ) ? . uintValue
45
+ else { return nil }
46
+ #else
33
47
guard let initialRect = ( userInfo [ UIKeyboardFrameBeginUserInfoKey] as? NSValue ) ? . cgRectValue,
34
48
let finalRect = ( userInfo [ UIKeyboardFrameEndUserInfoKey] as? NSValue ) ? . cgRectValue,
35
49
let duration = ( userInfo [ UIKeyboardAnimationDurationUserInfoKey] as? NSNumber ) ? . doubleValue,
36
50
let options = ( userInfo [ UIKeyboardAnimationCurveUserInfoKey] as? NSNumber ) ? . uintValue
37
51
else { return nil }
38
- let animationOptions = UIViewAnimationOptions ( rawValue: options) . union ( . beginFromCurrentState)
52
+ #endif
53
+ let animationOptions = AnimationOptions ( rawValue: options) . union ( . beginFromCurrentState)
39
54
self . init ( initialTransitionRect: initialRect,
40
55
finalTransitionRect: finalRect,
41
56
transitionDuration: duration,
@@ -154,9 +169,16 @@ fileprivate extension NotificationCenter
154
169
//MARK: - Notification + Keyboard Change Handler
155
170
fileprivate extension Notification
156
171
{
172
+ #if swift(>=4.2)
173
+ static var allKeyboardNotifications = [
174
+ UIResponder . keyboardWillChangeFrameNotification
175
+ ]
176
+ #else
157
177
static var allKeyboardNotifications = [
158
178
Notification . Name. UIKeyboardWillChangeFrame
159
179
]
180
+ #endif
181
+
160
182
161
183
var keyboardChange : Keyboard . Change ? {
162
184
guard Notification . allKeyboardNotifications. contains ( name) else { return nil }
0 commit comments