键盘显示/隐藏通知中心注册表正在为我的应用程序工作,一旦我更新到iOS 11或更高版本,键盘通知中心不工作?键盘显示/隐藏通知中心不适用于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
}
}
}
我该怎么做? 在此先感谢。
显示使用you're的代码。 –
我添加了代码 – user1553381
,您需要在keyboardWillShow和keyboardWillHide方法前添加@objc。 '@objc func keyboardWillHide(_ notification:Notification)'和'@objc func keyboardWillShow(_ notification:Notification)' –