我有一个聊天屏幕,它使用 View Controller 的 inputAccessoryView
来显示工具栏(用于文本输入、发送按钮+其他自定义类型),并在导航栏和底部边距之间有一个表格 View .
override var inputAccessoryView: UIView {
return inputToolbar
}
除了一种情况外,一切都很好; View Controller 的初始推送。当它被插入时,表格 View 的内容从输入附件 View 后面动画化。
我希望内容已经固定在输入附件 View 上方 - 有什么建议的方法可以实现此目的吗?
最佳答案
获取Indexpath并根据UIKeyboard高度更改UITableview内容偏移
func keyboardWillShow(notification: NSNotification) {
if ((notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue()) != nil {
//self.view.frame.origin.y -= keyboardSize.height
var userInfo = notification.userInfo!
var keyboardFrame:CGRect = (userInfo[UIKeyboardFrameBeginUserInfoKey] as! NSValue).CGRectValue()
keyboardFrame = self.view.convertRect(keyboardFrame, fromView: nil)
var contentInset:UIEdgeInsets = self.tbl.contentInset
contentInset.bottom = keyboardFrame.size.height
self.tbl.contentInset = contentInset
//get indexpath
let indexpath = NSIndexPath(forRow: 1, inSection: 0)
self.tbl.scrollToRowAtIndexPath(indexpath, atScrollPosition: UITableViewScrollPosition.Top, animated: true)
}
}
func keyboardWillHide(notification: NSNotification) {
if ((notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue()) != nil {
let contentInset:UIEdgeInsets = UIEdgeInsetsZero
self.tbl.contentInset = contentInset
}
}
关于ios - 防止键盘输入附件 View 引起的表格 View 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45796713/