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
......@@ -9,7 +9,9 @@
import UIKit
class YHInterestTopicLayout: UICollectionViewFlowLayout {
var dataSource:[String] = []
weak var layoutDelegate: UICollectionViewDelegateFlowLayout? = nil
var interItemSpacing: CGFloat = 12.0 // 相邻单元格之间的水平间距
override func prepare() {
super.prepare()
......@@ -48,4 +50,44 @@ class YHInterestTopicLayout: UICollectionViewFlowLayout {
}
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 {
typealias EditBlock = () -> ()
var editBlock: EditBlock?
static let cellReuseIdentifier = "YHMyInterestTopicCell"
weak var tableView: UITableView?
var topicArr:[String] = []
var userModel:YHUserNameCardInfo = YHUserNameCardInfo() {
didSet {
......@@ -71,23 +70,21 @@ class YHMyInterestTopicCell: UITableViewCell {
if self.userModel.topics.count > 0 {
self.topicArr.append(contentsOf: self.userModel.topics)
}
self.layout.dataSource = self.topicArr
self.collectionView.reloadData {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
let height = self.collectionView.contentSize.height
self.collectionView.snp.remakeConstraints { make in
make.height.equalTo(height)
make.left.equalTo(16)
make.right.equalTo(-16)
make.bottom.equalTo(-16)
make.top.equalTo(self.titleLabel.snp.bottom).offset(12)
}
self.detailLabel.snp.removeConstraints()
self.superview?.setNeedsLayout()
self.superview?.layoutIfNeeded()
})
let height = self.layout.collectionViewContentSize.height
printLog("ABC: \(height)")
self.collectionView.snp.remakeConstraints { make in
make.height.equalTo(height)
make.left.equalTo(16)
make.right.equalTo(-16)
make.bottom.equalTo(-16)
make.top.equalTo(self.titleLabel.snp.bottom).offset(12)
}
}
self.detailLabel.snp.removeConstraints()
} else {
self.detailLabel.snp.remakeConstraints { make in
......@@ -131,6 +128,8 @@ class YHMyInterestTopicCell: UITableViewCell {
lazy var layout:YHInterestTopicLayout = {
let layout = YHInterestTopicLayout()
layout.scrollDirection = .vertical
layout.dataSource = self.topicArr
layout.layoutDelegate = self
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