【问题标题】:UITableView Cell display issueUITableView 单元格显示问题
【发布时间】:2016-07-08 22:46:19
【问题描述】:

我有一个 UITableView,它到 superview 的顶部和底部距离为 0。 当键盘出现时,我更新底部约束,这样键盘就不会隐藏表格。但是在更新底部约束时,最后两个或三个单元格并不完全可见。我正在使用以下代码来更新底部约束。

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
    }
}

【问题讨论】:

  • 嗨,Aashish,你能添加一些故事板的图片和隐藏时的模拟器截图吗?
  • 带有 send 的视图在右下角,所以你需要把这个高度加到约束中然后试试。
  • 选项1:您还需要扣除自定义输入视图的高度。方案二:将你自定义的 inputview 添加为 ViewController 的 input accessoryView,然后它会自动为你管理。

标签: swift uitableview ios-autolayout


【解决方案1】:

您正在使用UIKeyboardFrameBeginUserInfoKey。这是换帧动画开始时键盘的大小。您最好使用UIKeyboardFrameEndUserInfoKey 以获得最终帧。

【讨论】:

  • 两种情况下键盘的高度相同。只有 y 位置发生变化。所以任何事情都应该是理想的。
  • Y 位置确实很重要。
【解决方案2】:

如果 x 是带有发送按钮的视图的高度。

if showsKeyboard
{
   cntInputViewBottom.constant = keyboardScreenBeginFrame.size.height+ x

}
else
{
     cntInputViewBottom.constant = x
}

【讨论】:

    【解决方案3】:

    问题是你没有通知你的视图/控制器在前后更新你的约束。

    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.layoutIfNeeded()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-07
      相关资源
      最近更新 更多