Swift UITableView单元格显示问题
我有一个UITableView,它的顶部和底部到superview的距离是0。 当键盘出现时,我更新底部约束,以便键盘不会隐藏表格。但在更新底部约束时,最后两个或三个单元格并不完全可见。我使用以下代码来更新底部约束Swift UITableView单元格显示问题,swift,uitableview,ios-autolayout,Swift,Uitableview,Ios Autolayout,我有一个UITableView,它的顶部和底部到superview的距离是0。 当键盘出现时,我更新底部约束,以便键盘不会隐藏表格。但在更新底部约束时,最后两个或三个单元格并不完全可见。我使用以下代码来更新底部约束 func keyboardWillChangeFrameWithNotification(notification: NSNotification, showsKeyboard: Bool) { let userInfo = notification.userInfo! le
func keyboardWillChangeFrameWithNotification(notification: NSNotification, showsKeyboard: Bool) {
let userInfo = notification.userInfo!
let animationDuration: NSTimeInterval = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as! NSNumber).doubleValue
// Convert the keyboard frame from screen to view coordinates.
let keyboardScreenBeginFrame = (userInfo[UIKeyboardFrameBeginUserInfoKey] as! NSValue).CGRectValue()
if showsKeyboard
{
cntInputViewBottom.constant = keyboardScreenBeginFrame.size.height
}
else
{
cntInputViewBottom.constant = 0
}
}
您正在使用
UIKeyboardFrameBeginUserInfo键
。这是帧更改动画开始时键盘的大小。您最好使用UIKeyboardFrameEndUserInfoKey
以获得最终帧。如果x是带有发送按钮的视图的高度
if showsKeyboard
{
cntInputViewBottom.constant = keyboardScreenBeginFrame.size.height+ x
}
else
{
cntInputViewBottom.constant = x
}
问题是您并没有在前后通知视图/控制器更新约束
if showsKeyboard
{
self.view.layoutIfNeeded()
cntInputViewBottom.constant = keyboardScreenBeginFrame.size.height
self.view.layoutIfNeeded()
}
else
{
self.view.layoutIfNeeded()
cntInputViewBottom.constant = 0
self.view.layoutIfNeeded()
}
只需添加显示的更新约束之前和之后的
self.view.layoutifneed()
。在这两种情况下,键盘的高度将相同。只有y位置改变。所以任何东西都应该是理想的。Y位置确实很重要。嗨,Aashish,你能添加一些故事板的图片和隐藏时的模拟器屏幕截图吗。带有send的视图在右下角,所以你需要将该高度添加到约束中并尝试。选项1:你还需要扣除自定义输入视图的高度。选项2:添加自定义inputview作为ViewController的输入访问视图,然后它将自动为您管理它。