Le registre du centre de notifications pour l'affichage/masquage du clavier fonctionnait pour mon application. Une fois mis à jour vers iOS 11 ou supérieur, le centre de notification du clavier ne fonctionnait pas?Le centre de notification pour afficher/masquer le clavier ne fonctionnait pas dans iOS 11
func registerNotificationObservers()
{
NotificationCenter.default.addObserver(self, selector: #selector(ArticleDetailsVC.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(ArticleDetailsVC.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
}
func removeNotificationObservers()
{
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillHide, object: nil)
}
func keyboardWillShow(notification: NSNotification)
{
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue
{
if self.commentsTableView.frame.origin.y == 0{
print("keyboardWillShow ..")
self.tableViewFooter.frame.origin.y -= keyboardSize.height - 50
self.commentsTableView.frame.origin.y -= keyboardSize.height
}
}
}
func keyboardWillHide(notification: NSNotification)
{
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue
{
if self.commentsTableView.frame.origin.y != 0{
print("keyboardWillHide ..")
self.tableViewFooter.frame.origin.y += keyboardSize.height + 50
self.commentsTableView.frame.origin.y += keyboardSize.height
}
}
}
Que devrais-je faire? Merci d'avance.
Afficher le code qui vous êtes à l'aide. –
J'ai ajouté le code – user1553381
, vous devez ajouter @objc devant vos méthodes keyboardWillShow et keyboardWillHide. '@objc func keyboardWillHide (_ notification: Notification)' et '@objc func keyboardWillShow (_ notification: Notification)' –