我在显示iPad上的虚拟键盘时使用此代码调整textView和tableView大小:
func keyboardWillShown(_ notification: Notification) {
var info = notification.userInfo!
let keyboardFrame: CGRect = (info[UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue
UIView.animate(withDuration: 0.5, animations: { () -> Void in
self.textView_bottomLayoutGuide.constant = keyboardFrame.size.height
self.tableView_bottomLayoutGuide.constant = keyboardFrame.size.height
})
}
func keyboardWillHide(_ notification: Notification) {
UIView.animate(withDuration: 0.5, animations: { () -> Void in
self.textView_bottomLayoutGuide.constant = 0
self.tableView_bottomLayoutGuide.constant = 0
})
}
虚拟键盘一切正常。使用Apple的物理iPad智能键盘,textView可以很好地适应(它只是保持计数快捷方式和预测条带)但是tableView行为是错误的:它自身短路,好像显示了一个虚拟键盘。