Skip to content
This repository was archived by the owner on Jul 1, 2020. It is now read-only.
This repository was archived by the owner on Jul 1, 2020. It is now read-only.

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

Description

@nirvana72

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions