Commit 77cfa604 authored by Steven杜宇's avatar Steven杜宇

// AI

parent ccdc9079
...@@ -168,7 +168,7 @@ extension YHAIRobotChatViewController: UITableViewDelegate, UITableViewDataSourc ...@@ -168,7 +168,7 @@ extension YHAIRobotChatViewController: UITableViewDelegate, UITableViewDataSourc
let view = YHAIChatBannerView() let view = YHAIChatBannerView()
let arr:[YHBannerModel] = [YHBannerModel(), YHBannerModel(), YHBannerModel()] let arr:[YHBannerModel] = [YHBannerModel(), YHBannerModel(), YHBannerModel()]
view.dataArr = arr view.dataArr = arr
view.historyItems = ["阿萨法吉林师范", "阿萨法", "啊设计立卡", "啊积", "阿基德拉屎就发了", "asfasf", "阿萨法", "啊设计立卡", "啊积", "阿基德拉屎就发了"] view.items = ["阿萨法吉林师范", "阿萨法阿基德拉屎就发了阿基德拉屎就发了阿基德拉屎就发了阿基德拉屎就发了阿基德拉屎就发了阿基德拉屎就发了阿基德拉屎就发了", "啊设计立卡", "啊积", "阿基德拉屎就发了", "asfasf", "阿萨法", "啊设计立卡", "啊积", "阿基德拉屎就发了"]
return view return view
} }
......
...@@ -14,9 +14,9 @@ class YHAIChatBannerView: UIView { ...@@ -14,9 +14,9 @@ class YHAIChatBannerView: UIView {
static let bannerHeight = 242.0 static let bannerHeight = 242.0
let cellHeight: CGFloat = 33.0 // 单元格的固定高度 let cellHeight: CGFloat = 33.0 // 单元格的固定高度
var historyItems:[String] = [] { var items:[String] = [] {
didSet { didSet {
layout.dataSource = historyItems layout.dataSource = items
collectionView.reloadData() collectionView.reloadData()
} }
} }
...@@ -156,7 +156,7 @@ extension YHAIChatBannerView: UICollectionViewDelegate, UICollectionViewDataSour ...@@ -156,7 +156,7 @@ extension YHAIChatBannerView: UICollectionViewDelegate, UICollectionViewDataSour
// 返回单元格数量 // 返回单元格数量
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return historyItems.count return items.count
} }
// 返回每个单元格的大小 // 返回每个单元格的大小
...@@ -168,15 +168,15 @@ extension YHAIChatBannerView: UICollectionViewDelegate, UICollectionViewDataSour ...@@ -168,15 +168,15 @@ extension YHAIChatBannerView: UICollectionViewDelegate, UICollectionViewDataSour
// 返回自定义单元格 // 返回自定义单元格
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: YHAIChatBannerCollectionCell.cellReuseIdentifier, for: indexPath) as! YHAIChatBannerCollectionCell let cell = collectionView.dequeueReusableCell(withReuseIdentifier: YHAIChatBannerCollectionCell.cellReuseIdentifier, for: indexPath) as! YHAIChatBannerCollectionCell
if 0 <= indexPath.item && indexPath.item < historyItems.count { if 0 <= indexPath.item && indexPath.item < items.count {
cell.titleLabel.text = historyItems[indexPath.item] cell.titleLabel.text = items[indexPath.item]
} }
return cell return cell
} }
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if 0 <= indexPath.item && indexPath.item < historyItems.count { if 0 <= indexPath.item && indexPath.item < items.count {
let text = historyItems[indexPath.item] let text = items[indexPath.item]
} }
} }
} }
...@@ -13,10 +13,36 @@ class YHAIChatCustomFlowLayout: UICollectionViewFlowLayout { ...@@ -13,10 +13,36 @@ class YHAIChatCustomFlowLayout: UICollectionViewFlowLayout {
let cellHeight = 33.0 let cellHeight = 33.0
let verticalGap = 10.0 let verticalGap = 10.0
let horizonalGap = 10.0 let horizonalGap = 10.0
var firstLineX: CGFloat = 0.0 var firstLineX = 0.0
var secondLineX: CGFloat = 0.0 var secondLineX = 0.0
let firstLineY = 10.0
let secondLineY = 10.0 + 33.0 + 10.0
var attributes: [UICollectionViewLayoutAttributes] = [] var attributes: [UICollectionViewLayoutAttributes] = []
// var dataSource:[String] = [] {
// didSet {
// attributes.removeAll()
// firstLineX = 0.0
// secondLineX = 0.0
// for (index, text) in dataSource.enumerated() {
// let attribute = UICollectionViewLayoutAttributes(forCellWith: IndexPath(row: index, section: 0))
// if index % 2 == 0 { // 第一行的数据
// let size = self.getSize(index: index)
// attribute.frame = CGRectMake(firstLineX, verticalGap, size.width, size.height)
// firstLineX = firstLineX + attribute.frame.width + horizonalGap
//
// } else { // 第二行的数据
// let size = self.getSize(index: index)
// attribute.frame = CGRectMake(secondLineX, verticalGap+cellHeight+verticalGap, size.width, size.height)
// secondLineX = secondLineX + attribute.frame.width + horizonalGap
// }
// attributes.append(attribute)
// }
// collectionView?.reloadData()
// }
// }
var dataSource:[String] = [] { var dataSource:[String] = [] {
didSet { didSet {
attributes.removeAll() attributes.removeAll()
...@@ -24,14 +50,14 @@ class YHAIChatCustomFlowLayout: UICollectionViewFlowLayout { ...@@ -24,14 +50,14 @@ class YHAIChatCustomFlowLayout: UICollectionViewFlowLayout {
secondLineX = 0.0 secondLineX = 0.0
for (index, text) in dataSource.enumerated() { for (index, text) in dataSource.enumerated() {
let attribute = UICollectionViewLayoutAttributes(forCellWith: IndexPath(row: index, section: 0)) let attribute = UICollectionViewLayoutAttributes(forCellWith: IndexPath(row: index, section: 0))
if index % 2 == 0 { // 第一行的数据 let size = self.getSize(index: index)
let size = self.getSize(index: index)
attribute.frame = CGRectMake(firstLineX, verticalGap, size.width, size.height) if firstLineX <= secondLineX {
attribute.frame = CGRectMake(firstLineX, firstLineY, size.width, size.height)
firstLineX = firstLineX + attribute.frame.width + horizonalGap firstLineX = firstLineX + attribute.frame.width + horizonalGap
} else { // 第二行的数据 } else {
let size = self.getSize(index: index) attribute.frame = CGRectMake(secondLineX, secondLineY, size.width, size.height)
attribute.frame = CGRectMake(secondLineX, verticalGap+cellHeight+verticalGap, size.width, size.height)
secondLineX = secondLineX + attribute.frame.width + horizonalGap secondLineX = secondLineX + attribute.frame.width + horizonalGap
} }
attributes.append(attribute) attributes.append(attribute)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment