diff --git a/Source/AlertController.swift b/Source/AlertController.swift index 8ee2ea0..6d82f24 100644 --- a/Source/AlertController.swift +++ b/Source/AlertController.swift @@ -289,12 +289,15 @@ public final class AlertController: UIViewController { private func listenForKeyboardChanges() { NotificationCenter.default - .addObserver(self, selector: #selector(self.keyboardChange), - name: UIResponder.keyboardWillChangeFrameNotification, object: nil) + .addObserver(self, selector: #selector(keyboardWillShow), + name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default + .addObserver(self, selector: #selector(keyboardWillHide), + name: UIResponder.keyboardWillHideNotification, object: nil) } @objc - private func keyboardChange(_ notification: Notification) { + private func keyboardWillShow(notification: NSNotification) { let newFrameValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue guard let newFrame = newFrameValue?.cgRectValue else { return @@ -304,6 +307,12 @@ public final class AlertController: UIViewController { self.alert.layoutIfNeeded() } + @objc + private func keyboardWillHide(notification: NSNotification) { + self.verticalCenter?.constant = 0 + self.alert.layoutIfNeeded() + } + private func configureAlertView() { self.alert.translatesAutoresizingMaskIntoConstraints = false self.alert.visualStyle = self.visualStyle