ios - 防止键盘输入附件 View 引起的表格 View 动画

标签 ios swift uitableview inputaccessoryview

我有一个聊天屏幕,它使用 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/

相关文章:

ios - Tesseract iOS 相机精度低

ios - 当单元格被选中时,按钮的背景颜色会改变然后恢复

jquery - PWA - 添加到 iOS 上的主屏幕提示?

iOS - 在 segue 上意外旋转回纵向

ios - 如何等待给定时间并只执行最后一个函数调用

ios - 计算 Collection View 单元格内tableView高度的高度

ios - 在 Swift 中,如何强制键盘在程序启动时打开?

ios - 如何在不调用 textViewDidChangeSelection 的情况下设置 NSAttributedString 属性?

iOS 表格 View ——我不知道这是否可行

ios - 如何显示放置在 UIView .xib 文件中的 UITableView?