NotificationCenter keyboard show hide

func setupViewResizerOnKeyboardShown() {

NotificationCenter.default.addObserver(self,
selector: #selector(self.keyboardWillShowForResizing),
name: Notification.Name.UIKeyboardWillShow,
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(self.keyboardWillHideForResizing),
name: Notification.Name.UIKeyboardWillHide,
object: nil)
}

func keyboardWillShowForResizing(notification: Notification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue,
let _ = self.view.window?.frame {
// We're not just minusing the kb height from the view height because
// the view could already have been resized for the keyboard before
if self.alertView != nil {
self.alertView.snp.makeConstraints({ (ConstraintMaker) in
ConstraintMaker.edges.equalTo(self.view).inset(UIEdgeInsets(top: (self.view.frame.size.height - self.alertView.frame.size.height) / 2, left: self.alertView.frame.origin.x, bottom: keyboardSize.height + 20, right: self.alertView.frame.origin.x))
})

}

} else {
debugPrint("We're showing the keyboard and either the keyboard size or window is nil: panic widely.")
}
}

func keyboardWillHideForResizing(notification: Notification) {
if ((notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue) != nil {
if self.alertView != nil {
self.alertView.snp.remakeConstraints({ (ConstraintMaker) in
ConstraintMaker.edges.equalTo(self.view).inset(UIEdgeInsets(top: 60, left: self.alertView.frame.origin.x, bottom: 60, right: self.alertView.frame.origin.x))
})

}
} else {
debugPrint("We're about to hide the keyboard and the keyboard size is nil. Now is the rapture.")
}
}