Commit 69de5da0 authored by David黄金龙's avatar David黄金龙

Merge branch '630-dev' of http://gitlab.galaxy-immi.com/mobile-group/galaxy-iOS into 630-dev

* '630-dev' of http://gitlab.galaxy-immi.com/mobile-group/galaxy-iOS:
  // 兴趣话题
parents 1a16fcf8 7cfb06d0
...@@ -10,6 +10,8 @@ import UIKit ...@@ -10,6 +10,8 @@ import UIKit
class YHInterestTopicLayout: UICollectionViewFlowLayout { class YHInterestTopicLayout: UICollectionViewFlowLayout {
var dataSource:[String] = []
weak var layoutDelegate: UICollectionViewDelegateFlowLayout? = nil
var interItemSpacing: CGFloat = 12.0 // 相邻单元格之间的水平间距 var interItemSpacing: CGFloat = 12.0 // 相邻单元格之间的水平间距
override func prepare() { override func prepare() {
super.prepare() super.prepare()
...@@ -48,4 +50,44 @@ class YHInterestTopicLayout: UICollectionViewFlowLayout { ...@@ -48,4 +50,44 @@ class YHInterestTopicLayout: UICollectionViewFlowLayout {
} }
return arrCell return arrCell
} }
override var collectionViewContentSize: CGSize {
get {
let width = self.collectionView?.width ?? 0.0
let height = self.calculateHeight()
return CGSize(width: width, height: height)
}
}
func calculateHeight() ->CGFloat {
if self.dataSource.count <= 0 {
return 0.0
}
guard let delegate = self.layoutDelegate else {
return 0.0
}
let itemHeight = 24.0
var currentX = 0.0
var height = itemHeight
for (index, _) in self.dataSource.enumerated() {
if delegate.responds(to: #selector(UICollectionViewDelegateFlowLayout.collectionView(_:layout:sizeForItemAt:))) {
let size = delegate.collectionView!(self.collectionView!, layout: self, sizeForItemAt: IndexPath(item: index, section: 0))
if index == 0 {
currentX = size.width
height = itemHeight
} else {
let targetX = currentX + self.minimumInteritemSpacing + size.width
if targetX <= self.collectionView!.width {
currentX = targetX
} else {
currentX = 0
height += self.minimumLineSpacing + itemHeight
}
}
}
}
return height
}
} }
...@@ -49,7 +49,6 @@ class YHMyInterestTopicCell: UITableViewCell { ...@@ -49,7 +49,6 @@ class YHMyInterestTopicCell: UITableViewCell {
typealias EditBlock = () -> () typealias EditBlock = () -> ()
var editBlock: EditBlock? var editBlock: EditBlock?
static let cellReuseIdentifier = "YHMyInterestTopicCell" static let cellReuseIdentifier = "YHMyInterestTopicCell"
weak var tableView: UITableView?
var topicArr:[String] = [] var topicArr:[String] = []
var userModel:YHUserNameCardInfo = YHUserNameCardInfo() { var userModel:YHUserNameCardInfo = YHUserNameCardInfo() {
didSet { didSet {
...@@ -71,10 +70,10 @@ class YHMyInterestTopicCell: UITableViewCell { ...@@ -71,10 +70,10 @@ class YHMyInterestTopicCell: UITableViewCell {
if self.userModel.topics.count > 0 { if self.userModel.topics.count > 0 {
self.topicArr.append(contentsOf: self.userModel.topics) self.topicArr.append(contentsOf: self.userModel.topics)
} }
self.layout.dataSource = self.topicArr
self.collectionView.reloadData { self.collectionView.reloadData {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { let height = self.layout.collectionViewContentSize.height
let height = self.collectionView.contentSize.height printLog("ABC: \(height)")
self.collectionView.snp.remakeConstraints { make in self.collectionView.snp.remakeConstraints { make in
make.height.equalTo(height) make.height.equalTo(height)
make.left.equalTo(16) make.left.equalTo(16)
...@@ -82,12 +81,10 @@ class YHMyInterestTopicCell: UITableViewCell { ...@@ -82,12 +81,10 @@ class YHMyInterestTopicCell: UITableViewCell {
make.bottom.equalTo(-16) make.bottom.equalTo(-16)
make.top.equalTo(self.titleLabel.snp.bottom).offset(12) make.top.equalTo(self.titleLabel.snp.bottom).offset(12)
} }
self.detailLabel.snp.removeConstraints()
self.superview?.setNeedsLayout()
self.superview?.layoutIfNeeded()
})
} }
self.detailLabel.snp.removeConstraints()
} else { } else {
self.detailLabel.snp.remakeConstraints { make in self.detailLabel.snp.remakeConstraints { make in
...@@ -131,6 +128,8 @@ class YHMyInterestTopicCell: UITableViewCell { ...@@ -131,6 +128,8 @@ class YHMyInterestTopicCell: UITableViewCell {
lazy var layout:YHInterestTopicLayout = { lazy var layout:YHInterestTopicLayout = {
let layout = YHInterestTopicLayout() let layout = YHInterestTopicLayout()
layout.scrollDirection = .vertical layout.scrollDirection = .vertical
layout.dataSource = self.topicArr
layout.layoutDelegate = self
return layout return layout
}() }()
......
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