PullToRefreshKit
PullToRefreshKit copied to clipboard
刚发现一个ios13下的BUG,同样代码ios12没问题

UICollectionViewCell高度自适应, 用的是自定义cell 中的 preferredLayoutAttributesFitting 方法来返回每个cell的经计算后的不同高度 下拉刷新时,崩溃了, IOS12下是好的,也在项目中用了好久了
最小重现代码如下: `import UIKit import PullToRefreshKit
class TestViewController: UIViewController, UICollectionViewDataSource { @IBOutlet weak var collectionView: UICollectionView! @IBOutlet weak var layout: UICollectionViewFlowLayout!
override func viewDidLoad() {
super.viewDidLoad()
layout.estimatedItemSize = CGSize(width: UIScreen.main.bounds.width, height: 0)
collectionView.dataSource = self
collectionView.register(MyCollectionViewCell.self, forCellWithReuseIdentifier: "cell")
let refreshHeader = ElasticRefreshHeader()
self.collectionView.configRefreshHeader(with: refreshHeader, container: self) { [weak self] in
print("refreshHeader")
self?.collectionView.switchRefreshHeader(to: .normal(.success, 0.5))
}
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 100
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! MyCollectionViewCell
cell.backgroundColor = UIColor.red
return cell
}
}
class MyCollectionViewCell: UICollectionViewCell { override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes { var newFrame = layoutAttributes.frame newFrame.size.height = 100 // 这里根据内容计算出每个cell的不同高度 layoutAttributes.frame = newFrame return layoutAttributes } }`
Any body Solve it ??