一、导航栏标题、副标题修改。在ChatBaseViewController,通过NSMutableAttributedString拼接标题、副标题,并换行。用到项目中,需在适当的位置传递attributedString给控件。
private func setuptitleUI() {
attributeTitle = NSMutableAttributedString(attributedString: NSAttributedString(string: "东莞西安南京急聘", attributes: [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 14, weight: .black)]))
let enterAttr = NSAttributedString(string: "\n", attributes: [:])
attributeTitle.append(enterAttr)
let subAttr = NSAttributedString(string: "某为技术有限公司-工程师", attributes: [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 12, weight: .regular), NSAttributedString.Key.foregroundColor: UIColor.gray])
attributeTitle.append(subAttr)
let titleLabel = UILabel()
titleLabel.numberOfLines = 2
titleLabel.textAlignment = .center
titleLabel.frame = CGRectMake(0, 0, 100, 64)
titleLabel.font = UIFont.systemFont(ofSize: 14, weight: .black)
navigationItem.titleView = titleLabel
titleLabel.attributedText = attributeTitle
}
二、反诈提示封装在CounterfraudView,聊天页面用约束添加在tableview上方。点了删除按钮,使其高度约束置为0。
view.addSubview(tableView)
counterfraudView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(counterfraudView)
if #available(iOS 10, *) {
NSLayoutConstraint.activate([
counterfraudView.topAnchor.constraint(
equalTo: view.topAnchor,
constant: kNavigationHeight + KStatusBarHeight
),
counterfraudView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 0),
counterfraudView.rightAnchor.constraint(equalTo: view.rightAnchor),
])
} else {
NSLayoutConstraint.activate([
counterfraudView.topAnchor.constraint(
equalTo: view.topAnchor,
constant: 0
),
counterfraudView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 0),
counterfraudView.rightAnchor.constraint(equalTo: view.rightAnchor),
])
}
NSLayoutConstraint.activate([
counterfraudView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 0),
counterfraudView.rightAnchor.constraint(equalTo: view.rightAnchor),
counterfraudView.bottomAnchor.constraint(equalTo: tableView.topAnchor),
])
counterfraudView.closeblock = { [self] in
counterfraudViewHeightConstraint = counterfraudView.heightAnchor.constraint(equalToConstant: 0)
counterfraudViewHeightConstraint?.isActive = true
}
counterfraudViewHeightConstraint = counterfraudView.heightAnchor.constraint(equalToConstant: 60)
counterfraudViewHeightConstraint?.isActive = true
tableViewBottomConstraint = tableView.bottomAnchor.constraint(
equalTo: view.bottomAnchor,
constant: -100
)
tableViewBottomConstraint?.isActive = true
NSLayoutConstraint.activate([
tableView.topAnchor.constraint(equalTo: counterfraudView.bottomAnchor, constant: 0),
tableView.leftAnchor.constraint(equalTo: view.leftAnchor),
tableView.rightAnchor.constraint(equalTo: view.rightAnchor),
])
三、输入框上加快捷按钮条,加快捷按钮封装在QuickBar里。
1、在ChatInputView里,增加quickBar,quickBar固定在textField顶部。
let quickBar = QuickBar()
addSubview(quickBar)
quickBar.backgroundColor = UIColor.lightText
quickBar.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
quickBar.leftAnchor.constraint(equalTo: leftAnchor, constant: 0),
quickBar.topAnchor.constraint(equalTo: topAnchor, constant: 0),
quickBar.rightAnchor.constraint(equalTo: rightAnchor, constant: 0),
quickBar.heightAnchor.constraint(equalToConstant: 40),
])
2、在ChatViewController,找到方法func layoutInputView(offset: CGFloat)修改输入框高度。修改高度menuView.heightAnchor.constraint(equalToConstant: 344)
/*
func layoutInputView(offset: CGFloat) {
print("layoutInputView offset : ", offset)
weak var weakSelf = self
UIView.animate(withDuration: 0.1, animations: {
weakSelf?.inputViewTopConstraint?.constant = -100 - offset
weakSelf?.tableViewBottomConstraint?.constant = -100 - offset
})
}
*/
func layoutInputView(offset: CGFloat) {
print("layoutInputView offset : ", offset)
weak var weakSelf = self
UIView.animate(withDuration: 0.1, animations: {
weakSelf?.inputViewTopConstraint?.constant = -140 - offset
weakSelf?.tableViewBottomConstraint?.constant = -140 - offset
})
}
四、增加PostResumeView,点击自定义会话里的“投递简历”,通过代理,以present方式弹出投递简历页面。以UItableView展示多份简历,按钮增加单选逻辑。根据选中第几个简历,在投递闭包里发送文件格式的消息。
public func didTapPostResume(_ cell: UITableViewCell, _ model: MessageContentModel?) {
let vc = PostResumeViewController()
let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first
let fileName = path! + "/test.txt"
let str:NSString = NSString(string: "简历\ndemo测试")
//进行写文件
do {
try str.write(toFile: fileName, atomically: true, encoding: 4)
}catch {
print("写入文件失败")
}
vc.startDatalist(datalist: ["简历","简历"])
vc.postBlock = { fileIndex in
self.viewmodel.sendFileMessage(filePath: fileName, displayName: "简历" + String(fileIndex)) { error in
print("发送文件失败")
}
vc.dismiss(animated: true)
}
self.navigationController?.present(vc, animated: true)
}
五、在ChatInputView增加常用语按钮,并粘贴PhrasesView页面,点击按钮触发页面弹出。通过代理将常用语cell的点击事件传递到ChatViewController,发送对应txt消息。
//初始化和粘贴常用语
public lazy var phrasesView: PhrasesView = {
let view = PhrasesView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 200))
view.translatesAutoresizingMaskIntoConstraints = false
view.isHidden = true
view.delegate = self
return view
}()
contentView.addSubview(phrasesView)
//点击常用语按钮
func buttonEvent(button: UIButton) {
switch button.tag - 5 {
case 0:
addRecordView()
case 1:
addEmojiView()
case 3:
addMoreActionView()
case 4:
clickPhrases()
default:
print("default")
}
delegate?.willSelectItem(button: button, index: button.tag - 5)
}
func clickPhrases() {
if currentType != .phrases {
currentType = .phrases
contentSubView?.isHidden = true
contentSubView = phrasesView
contentSubView?.isHidden = false
}else {
currentType = .text
}
}
//发送常用语
public func didSelectPhrasesCell(cell: PhrasesTableViewCell) {
sendText(text: cell.titleLabel.text)
}
六、修改底部功能布局。在NEMoreActionType增加一种类型,再在NEChatUIKitClient类里面,moreAction数组新增一个NEMoreItemModel。点击事件,实现ChatViewController里的代理:public func didSelectMoreCell(cell: NEInputMoreCell)。
let resume = NEMoreItemModel()
resume.image = UIImage.ne_imageNamed(name: "chat_file")
resume.title = chatLocalizable("更换职位")
resume.type = .file
moreAction.append(resume)
public func didSelectMoreCell(cell: NEInputMoreCell)
七、删除信息的bug修改,serverID修改为messageId。
func deleteMessageUpdateUI(_ message: NIMMessage)
if model.message?.messageId == message.messageId {