修改了登录im的逻辑
This commit is contained in:
@@ -9,25 +9,39 @@ import UIKit
|
||||
import NIMSDK
|
||||
class ChatVC: BaseViewController {
|
||||
|
||||
// 键盘收起/弹出 滚动的时候收起输入栏
|
||||
private var isBecome: Bool = false
|
||||
/// 是否发送完成
|
||||
private var isSended: Bool = true
|
||||
/// 输入栏默认的高度
|
||||
private let ToolBarLastH: CGFloat = 52
|
||||
|
||||
public init(session: NIMSession) {
|
||||
vm = ChatViewModel(session: session)
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
// vm.delegate = self
|
||||
// NIMSDK.shared().mediaManager.add(self)
|
||||
}
|
||||
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
|
||||
var vm:ChatViewModel
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
view.backgroundColor = .orange
|
||||
}
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
view.backgroundColor = ThemeColor(hexStr: "#F6F6F6")
|
||||
let height = ScreenHeight - (ToolBarLastH + SafeAraeBottomHeight + NavHeight)
|
||||
chatTableView.frame = CGRect(x: 0, y: 0, width: ScreenWidth, height: height)
|
||||
view.addSubview(chatTableView)
|
||||
view.addSubview(keyboardView)
|
||||
}
|
||||
|
||||
///注册cell
|
||||
private func registerChatCell() {
|
||||
chatTableView.register(cellType: ChatTextCell.self)
|
||||
}
|
||||
|
||||
private lazy var chatTableView: UITableView = {
|
||||
let tableView = UITableView(frame: .zero, style: .plain)
|
||||
@@ -42,20 +56,57 @@ class ChatVC: BaseViewController {
|
||||
return tableView
|
||||
}()
|
||||
|
||||
private lazy var keyboardView: ChatKeyboardView = {
|
||||
let toolBarY = ScreenHeight - NavHeight - ToolBarLastH - SafeAraeBottomHeight
|
||||
let view = ChatKeyboardView(frame: CGRect(x: 0, y: toolBarY, width: ScreenWidth, height: ToolBarLastH))
|
||||
view.delegate = self
|
||||
return view
|
||||
}()
|
||||
|
||||
}
|
||||
|
||||
extension ChatVC: UITableViewDelegate, UITableViewDataSource {
|
||||
// MARK: - ChatKeyboardViewDelegate
|
||||
extension ChatVC: ChatKeyboardViewDelegate {
|
||||
|
||||
func keyboard(_ keyboard: ChatKeyboardView, DidFinish content: String) {
|
||||
///发送消息
|
||||
vm.sendTextMessage(text: content) { error in
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func keyboard(_ keyboard: ChatKeyboardView, DidBecome isBecome: Bool) {
|
||||
self.isSended = true
|
||||
self.isBecome = isBecome
|
||||
}
|
||||
|
||||
func keyboard(_ keyboard: ChatKeyboardView, DidMoreMenu type: ChatMoreMenuType) {
|
||||
|
||||
//TODO: 点击更多
|
||||
}
|
||||
|
||||
func keyboard(_ keyboard: ChatKeyboardView, DidObserver offsetY: CGFloat) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
extension ChatVC: UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate {
|
||||
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
return vm.messageObjects.count
|
||||
}
|
||||
|
||||
public func tableView(_ tableView: UITableView,
|
||||
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
let model = vm.messageObjects[safe: indexPath.row]
|
||||
if model?.type == .text {
|
||||
let cell = tableView.dequeueReusableCell(for: indexPath, cellType: ChatTextCell.self)
|
||||
cell.model = model
|
||||
}
|
||||
return UITableViewCell()
|
||||
}
|
||||
|
||||
public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
|
||||
tableView.deselectRow(at: indexPath, animated: true)
|
||||
}
|
||||
|
||||
public func tableView(_ tableView: UITableView,
|
||||
@@ -63,4 +114,22 @@ extension ChatVC: UITableViewDelegate, UITableViewDataSource {
|
||||
let m = vm.messageObjects[safe:indexPath.row]
|
||||
return CGFloat(m?.height ?? 0)
|
||||
}
|
||||
|
||||
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
|
||||
if isSended {
|
||||
isSended = false
|
||||
}
|
||||
}
|
||||
|
||||
func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
||||
if isSended {
|
||||
return
|
||||
}
|
||||
|
||||
if chatTableView.y <= 0 && isBecome {
|
||||
DispatchQueue.main.async {
|
||||
NotificationCenter.default.post(name: .kChatTextKeyboardNeedHide, object: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user