滚动表格时如何在键盘上方移动inputView [英] how to move inputView above keyboard when scrolling the table

查看:57
本文介绍了滚动表格时如何在键盘上方移动inputView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图控制器,其中 表格视图和表格下方的textView

I have a view controller in which it has table view and textView below the table

当我点击textView时,出现键盘,而当我点击textView之外时,键盘消失 效果很好,但是我有一个问题,当我拖动(向下滚动)表格视图时,textView不会随着键盘向下移动,并且在键盘后面看到黑色背景,如下图所示

When I tap on the textView the keyboard appears and when I tap outside the textView the keyboard disappar That works fine but I have one problem which is when I Drag(scroll Down) the table view the textView doesn't move down with the keyboard and I see black background behind the keyboard as in the below image

如何在Swift中解决此问题

How to solve this problem in Swift

更新: 这是我当前的代码,其中观察到keyboardFrameChanges

Update: This is my current code that observe the keyboardFrameChanges

func keyboardFrameChanged(notification: NSNotification) {

    let dict = NSDictionary(dictionary: notification.userInfo!)
    let keyboardValue = dict.objectForKey(UIKeyboardFrameEndUserInfoKey) as! NSValue
    let bottomDistance = mainScreenSize().height - keyboardValue.CGRectValue().origin.y
     let duration = Double(dict.objectForKey(UIKeyboardAnimationDurationUserInfoKey) as! NSNumber)

    UIView.animateWithDuration(duration, animations: {
        self.inputViewConstraint!.constant = -bottomDistance
        self.view.layoutIfNeeded()
        }, completion: {
            (value: Bool) in
            self.chatTableView.scrollToBottom(animation: true)
    })

}

更新2: 我通过将keyboardDismissMode从 Interactive 更改为 OnDrag

Update 2: I found a solution by changing the keyboardDismissMode from Interactive to OnDrag

chatTableView.keyboardDismissMode = UIScrollViewKeyboardDismissMode.OnDrag

一旦观察到表格中的任何拖动移动,这将立即将键盘和textView向下移动,但是如何在 Interactive 模式下(如在whatsapp聊天视图中)进行操作

This will move the keyboard and the textView immediatly to down once it observe any drag movement in the table , But how to do it in the Interactive mode like in the whatsapp chat view

推荐答案

我找到了一个解决方案,方法是将keyboardDismissMode从Interactive更改为OnDrag

I found a solution by changing the keyboardDismissMode from Interactive to OnDrag

chatTableView.keyboardDismissMode = UIScrollViewKeyboardDismissMode.OnDrag

一旦观察到表格中的任何拖动运动,它将立即将键盘和textView向下移动

This will move the keyboard and the textView immediatly to down once it observe any drag movement in the table

这篇关于滚动表格时如何在键盘上方移动inputView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆