Skip to content

Instantly share code, notes, and snippets.

@matkuznik
Created May 18, 2021 13:11
Show Gist options
  • Save matkuznik/d57e6f64a5eeb87884788cb1c56a2085 to your computer and use it in GitHub Desktop.
Save matkuznik/d57e6f64a5eeb87884788cb1c56a2085 to your computer and use it in GitHub Desktop.
class KeyboardAppearListener {
private var showKeyboard: NotificationToken?
private var hideKeyboard: NotificationToken?
private weak var viewController: UIViewController?
init(
_ viewController: UIViewController,
notificationCenter: NotificationCenter = .default) {
self.viewController = viewController
showKeyboard = notificationCenter.observe(
name: UIResponder.keyboardWillShowNotification) { [weak self] (notification) in
self?.keyboardWillShow(notification: notification)
}
hideKeyboard = notificationCenter.observe(
name: UIResponder.keyboardWillHideNotification) { [weak self] (notification) in
self?.keyboardWillHide(notification: notification)
}
}
private func keyboardWillShow(notification: Notification) {}
private func keyboardWillHide(notification: Notification) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment