SDCAlertView
SDCAlertView copied to clipboard
AlertView offset is not restored after dismissing keyboard
I am using
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard))
tap.cancelsTouchesInView = false
alert.contentView.addGestureRecognizer(tap)
and
@objc func dismissKeyboard() {
alert.contentView.endEditing(true)
}
to dismiss keyboard when blank area is tapped, the alertview stay at the position where it was pushed to by keyboard.
Thanks for reporting, I'll try to look at this soon.
Fixed it temporarily by saving the Y offset for the popup view, when the keyboard shows/hides, and then setting the y offset on these events.
I think this is fixed on https://github.com/sberrevoets/SDCAlertView/tree/handle-keyboard-dismiss.
Can you check it out and see if this solves your problem?
Not working on my side.
@mureatencio on the branch I provided above? I was able to reproduce the issue, but not anymore on that branch.
In function listenForKeyboardChanges I replace function with
private func listenForKeyboardChanges() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
}
and add two function with
@objc private func keyboardWillShow(notification: NSNotification) {
let newFrameValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue
guard let newFrame = newFrameValue?.cgRectValue else {
return
}
self.verticalCenter?.constant = -newFrame.height / 2
self.alert.layoutIfNeeded()
}
@objc private func keyboardWillHide(notification: NSNotification){
self.verticalCenter?.constant = 0
self.alert.layoutIfNeeded()
}
Did you change master or handle-keyboard-dismiss branch? I've tried both and it doesn't work on master and on handle-keyboard-dismiss I'm getting crash on device when accessing alert.contentView (just after AlertController creation).
I'm not aware of any changes that would cause a crash, though the other branch is obviously a bit outdated at this point.
Can you tell me how to implement this keyboard dismiss fix on master branch?
The change above suggested by @x10geeky worked fine for me. 👏
@twostraws in here suggested that keyboardWillChangeFrameNotification
isn't enough to catch scenarios with a hardware keyboard being connected.
Any chance to get that on the master branch?