【发布时间】:2018-03-26 09:33:54
【问题描述】:
我正在使用以下代码在显示/隐藏键盘时滚动 UITableView 及其页脚。它在 iOS 10 中运行良好,但是一旦我更新到 iOS 11,滚动就无法正常工作。
代码:
func registerNotificationObservers()
{
NotificationCenter.default.addObserver(self, selector: #selector(ArticleDetailsVC.keyboardWillShow), name: .UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector:#selector(ArticleDetailsVC.keyboardWillHide), name: .UIKeyboardWillHide, object: nil)
}
func removeNotificationObservers()
{
NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillShow, object: nil)
NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillHide, object: nil)
}
@objc func keyboardWillShow(_ notification: Notification) {
print("keyboardWillShow")
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
}
}
}
@objc func keyboardWillHide(_ notification: Notification) {
print("keyboardWillHide")
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
}
}
}
希望能解决这个问题。
【问题讨论】:
标签: ios swift uitableview keyboard