LeoMobileDeveloper / PullToRefreshKit

【Deprecated】Pull to refresh in Swift, easy to use, easy to customize(下拉刷新/QQ/淘宝/优酷/雅虎天气/大众点评)
MIT License
554 stars 84 forks source link

刚发现一个ios13下的BUG,同样代码ios12没问题 #53

Open nirvana72 opened 5 years ago

nirvana72 commented 5 years ago

image

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 } }`

musbah98 commented 4 years ago

Any body Solve it ??