Skip to content

Commit f3cafd1

Browse files
committed
Cleanup
1 parent d320749 commit f3cafd1

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

KeyboardLayoutGuide/KeyboardLayoutGuide/Keyboard+LayoutGuide.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public extension UIView {
1414
static var keyboardLayoutGuide = "keyboardLayoutGuide"
1515
}
1616

17+
/// A layout guide representing the inset for the keyboard.
18+
/// Use this layout guide’s top anchor to create constraints pinning to the top of the keyboard.
1719
public var keyboardLayoutGuide: KeyboardLayoutGuide {
1820
get {
1921
if let obj = objc_getAssociatedObject(self, &AssociatedKeys.keyboardLayoutGuide) as? KeyboardLayoutGuide {
@@ -28,9 +30,7 @@ public extension UIView {
2830
}
2931
}
3032

31-
public class KeyboardLayoutGuide: UILayoutGuide {
32-
33-
private var token: NSKeyValueObservation? = nil
33+
open class KeyboardLayoutGuide: UILayoutGuide {
3434

3535
public required init?(coder aDecoder: NSCoder) {
3636
fatalError("init(coder:) has not been implemented")
@@ -51,10 +51,12 @@ public class KeyboardLayoutGuide: UILayoutGuide {
5151
guard let view = owningView else {
5252
return
5353
}
54-
heightAnchor.constraint(equalToConstant: 0).isActive = true
55-
leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
56-
rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
57-
let viewBottomAnchor: NSLayoutYAxisAnchor!
54+
NSLayoutConstraint.activate([
55+
heightAnchor.constraint(equalToConstant: 0),
56+
leftAnchor.constraint(equalTo: view.leftAnchor),
57+
rightAnchor.constraint(equalTo: view.rightAnchor),
58+
])
59+
let viewBottomAnchor: NSLayoutYAxisAnchor
5860
if #available(iOS 11.0, *) {
5961
viewBottomAnchor = view.safeAreaLayoutGuide.bottomAnchor
6062
} else {
@@ -64,7 +66,7 @@ public class KeyboardLayoutGuide: UILayoutGuide {
6466
}
6567

6668
@objc
67-
func keyboardWillChangeFrame(_ note: Notification) {
69+
private func keyboardWillChangeFrame(_ note: Notification) {
6870
if var height = note.keyboardHeight {
6971
if #available(iOS 11.0, *), height > 0 {
7072
height -= (owningView?.safeAreaInsets.bottom)!
@@ -92,7 +94,7 @@ public class KeyboardLayoutGuide: UILayoutGuide {
9294
// MARK: - Helpers
9395

9496
extension UILayoutGuide {
95-
var heightConstraint: NSLayoutConstraint? {
97+
internal var heightConstraint: NSLayoutConstraint? {
9698
guard let target = owningView else { return nil }
9799
for c in target.constraints {
98100
if let fi = c.firstItem as? UILayoutGuide, fi == self && c.firstAttribute == .height {

0 commit comments

Comments
 (0)