From 17add6fe3479ddf6ea9f3ac1b696c67ee96eeae2 Mon Sep 17 00:00:00 2001 From: S4cha Date: Fri, 8 Dec 2017 11:28:40 +0100 Subject: [PATCH 1/2] Fixes iOS 11 issue --- .../Keyboard+LayoutGuide.swift | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/KeyboardLayoutGuide/KeyboardLayoutGuide/Keyboard+LayoutGuide.swift b/KeyboardLayoutGuide/KeyboardLayoutGuide/Keyboard+LayoutGuide.swift index 736ee24..d08973e 100644 --- a/KeyboardLayoutGuide/KeyboardLayoutGuide/Keyboard+LayoutGuide.swift +++ b/KeyboardLayoutGuide/KeyboardLayoutGuide/Keyboard+LayoutGuide.swift @@ -8,6 +8,11 @@ import UIKit +private class Keyboard { + static let shared = Keyboard() + var currentHeight: CGFloat = 0 +} + public extension UIView { private struct AssociatedKeys { @@ -51,11 +56,21 @@ open class KeyboardLayoutGuide: UILayoutGuide { guard let view = owningView else { return } - NSLayoutConstraint.activate([ - heightAnchor.constraint(equalToConstant: 0), - leftAnchor.constraint(equalTo: view.leftAnchor), - rightAnchor.constraint(equalTo: view.rightAnchor), - ]) + + if #available(iOS 11.0, *) { + NSLayoutConstraint.activate([ + heightAnchor.constraint(equalToConstant: Keyboard.shared.currentHeight), + leftAnchor.constraint(equalTo: view.leftAnchor), + rightAnchor.constraint(equalTo: view.rightAnchor), + ]) + } else { + NSLayoutConstraint.activate([ + heightAnchor.constraint(equalToConstant: 0), + leftAnchor.constraint(equalTo: view.leftAnchor), + rightAnchor.constraint(equalTo: view.rightAnchor), + ]) + } + let viewBottomAnchor: NSLayoutYAxisAnchor if #available(iOS 11.0, *) { viewBottomAnchor = view.safeAreaLayoutGuide.bottomAnchor @@ -73,6 +88,9 @@ open class KeyboardLayoutGuide: UILayoutGuide { } heightConstraint?.constant = height animate(note) + if #available(iOS 11.0, *) { + Keyboard.shared.currentHeight = height + } } } From 70c1c55742dd9db11976ac2075074151e148b642 Mon Sep 17 00:00:00 2001 From: S4cha Date: Tue, 12 Dec 2017 11:13:47 +0100 Subject: [PATCH 2/2] Apply fix to all iOS versions --- .../Keyboard+LayoutGuide.swift | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/KeyboardLayoutGuide/KeyboardLayoutGuide/Keyboard+LayoutGuide.swift b/KeyboardLayoutGuide/KeyboardLayoutGuide/Keyboard+LayoutGuide.swift index d08973e..5f59fd6 100644 --- a/KeyboardLayoutGuide/KeyboardLayoutGuide/Keyboard+LayoutGuide.swift +++ b/KeyboardLayoutGuide/KeyboardLayoutGuide/Keyboard+LayoutGuide.swift @@ -56,21 +56,11 @@ open class KeyboardLayoutGuide: UILayoutGuide { guard let view = owningView else { return } - - if #available(iOS 11.0, *) { - NSLayoutConstraint.activate([ - heightAnchor.constraint(equalToConstant: Keyboard.shared.currentHeight), - leftAnchor.constraint(equalTo: view.leftAnchor), - rightAnchor.constraint(equalTo: view.rightAnchor), - ]) - } else { - NSLayoutConstraint.activate([ - heightAnchor.constraint(equalToConstant: 0), - leftAnchor.constraint(equalTo: view.leftAnchor), - rightAnchor.constraint(equalTo: view.rightAnchor), - ]) - } - + NSLayoutConstraint.activate([ + heightAnchor.constraint(equalToConstant: Keyboard.shared.currentHeight), + leftAnchor.constraint(equalTo: view.leftAnchor), + rightAnchor.constraint(equalTo: view.rightAnchor), + ]) let viewBottomAnchor: NSLayoutYAxisAnchor if #available(iOS 11.0, *) { viewBottomAnchor = view.safeAreaLayoutGuide.bottomAnchor @@ -88,9 +78,7 @@ open class KeyboardLayoutGuide: UILayoutGuide { } heightConstraint?.constant = height animate(note) - if #available(iOS 11.0, *) { - Keyboard.shared.currentHeight = height - } + Keyboard.shared.currentHeight = height } }