Skip to content

Commit

Permalink
Implement fix for: AlertView offset is not restored after dismissing … (
Browse files Browse the repository at this point in the history
#324)

Co-authored-by: swilliams <[email protected]>
  • Loading branch information
scottcwilliams511 and pni-swilliams authored Feb 2, 2023
1 parent 904e119 commit 8ecca43
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Source/AlertController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 8ecca43

Please sign in to comment.