Skip to content

Commit 17add6f

Browse files
committed
Fixes iOS 11 issue
1 parent 10d84e1 commit 17add6f

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

KeyboardLayoutGuide/KeyboardLayoutGuide/Keyboard+LayoutGuide.swift

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
import UIKit
1010

11+
private class Keyboard {
12+
static let shared = Keyboard()
13+
var currentHeight: CGFloat = 0
14+
}
15+
1116
public extension UIView {
1217

1318
private struct AssociatedKeys {
@@ -51,11 +56,21 @@ open class KeyboardLayoutGuide: UILayoutGuide {
5156
guard let view = owningView else {
5257
return
5358
}
54-
NSLayoutConstraint.activate([
55-
heightAnchor.constraint(equalToConstant: 0),
56-
leftAnchor.constraint(equalTo: view.leftAnchor),
57-
rightAnchor.constraint(equalTo: view.rightAnchor),
58-
])
59+
60+
if #available(iOS 11.0, *) {
61+
NSLayoutConstraint.activate([
62+
heightAnchor.constraint(equalToConstant: Keyboard.shared.currentHeight),
63+
leftAnchor.constraint(equalTo: view.leftAnchor),
64+
rightAnchor.constraint(equalTo: view.rightAnchor),
65+
])
66+
} else {
67+
NSLayoutConstraint.activate([
68+
heightAnchor.constraint(equalToConstant: 0),
69+
leftAnchor.constraint(equalTo: view.leftAnchor),
70+
rightAnchor.constraint(equalTo: view.rightAnchor),
71+
])
72+
}
73+
5974
let viewBottomAnchor: NSLayoutYAxisAnchor
6075
if #available(iOS 11.0, *) {
6176
viewBottomAnchor = view.safeAreaLayoutGuide.bottomAnchor
@@ -73,6 +88,9 @@ open class KeyboardLayoutGuide: UILayoutGuide {
7388
}
7489
heightConstraint?.constant = height
7590
animate(note)
91+
if #available(iOS 11.0, *) {
92+
Keyboard.shared.currentHeight = height
93+
}
7694
}
7795
}
7896

0 commit comments

Comments
 (0)