Skip to content

Instantly share code, notes, and snippets.

let windowSafeArea: CGFloat = windowsSafeAreaWereAdded ? 0 : viewController.view.safeAreaInsets.bottom - viewController.additionalSafeAreaInsets.bottom
viewController.additionalSafeAreaInsets.bottom += beginKeyboardBounds.origin.y - endKeyboardBounds.origin.y - windowSafeArea
windowsSafeAreaWereAdded = true
let duration = userInfo[UIResponder.keyboardAnimationDurationUserInfoKey]
.flatMap { $0 as? Double } ?? 0.25
if duration > 0 {
let curve = userInfo[UIResponder.keyboardAnimationCurveUserInfoKey]
.flatMap { $0 as? Int }
.flatMap { UIView.AnimationCurve(rawValue: $0) } ?? .easeInOut
UIViewPropertyAnimator(duration: duration, curve: curve) {
viewController.view.layoutIfNeeded()
}
.startAnimation()
import Foundation
class KeyboardAppearListener {
private var showKeyboard: NotificationToken?
private var hideKeyboard: NotificationToken?
private weak var viewController: UIViewController?
private var windowSafeArea: CGFloat = 0
private var windowsSafeAreaWereAdded = false