美文网首页
3 聊天界面点击return发送问题?

3 聊天界面点击return发送问题?

作者: Dayu大鱼 | 来源:发表于2018-01-13 09:21 被阅读9次

lastReturn数据只会在下一次进入聊天界面的时候才会向上移动??

方法① : 代码是用contentSize的方式写的 , 就出现了上面的👆情况 ;
方法② : 使用scrollToRow:

点击return之后,数据就会刷新, 数组就会多加一个数据 , 通过判断 (最新数据的个数 -1 ) 就是scrollVIew要跳转的行数

执行跳转:

 滚动到最新消息位置

    func scrollToBottom(_ scrollView:UIScrollView,animated:Bool) {
        
        //FIXME: 之前用到contentSize 和 bounds 的高度差来移动,最新的数据总是会在下一次才上移
        if self.chatMsgs.count == 0 {
            return
        }
        let lastIndexPath =  IndexPath(row: self.chatMsgs.count - 1, section: 0)

        self.tableView?.scrollToRow(at: lastIndexPath, at: UITableViewScrollPosition.bottom, animated: true)
        
        }

相关文章

网友评论

      本文标题:3 聊天界面点击return发送问题?

      本文链接:https://www.haomeiwen.com/subject/kpzqoxtx.html