防止键盘输入附件视图导致的表视图动画

时间:2017-08-21 12:06:07

标签: ios swift uitableview inputaccessoryview

我有一个聊天屏幕,它使用视图控制器的inputAccessoryView来显示工具栏(用于文本输入,发送按钮+其他自定义类型),并在导航栏和底部之间有一个表格视图边距。

override var inputAccessoryView: UIView {
    return inputToolbar
}

除了一个案例外,一切都很好;视图控制器的初始推送。当它被推开时,表格视图的内容从后面动画输入附件视图。

我希望内容已经修复输入附件视图 - 任何建议的实现方式?

1 个答案:

答案 0 :(得分:0)

获取Indexpath并根据UIKeyboard Height更改UITableview内容Offset

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