滚动时水平集合视图冻结
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了滚动时水平集合视图冻结相关的知识,希望对你有一定的参考价值。
我在一个具有单独视图的同一个viewcontroller中有一个collectionView和tableview。我正在使用Kingfisher下载图像。我可以毫无问题地滚动tableview。但是当我滚动collectionview时,应用程序会冻结,并且在一段时间后应用程序崩溃并将调试消息作为“来自调试器的消息:由于内存问题而终止”。
func setupCollectionView(){
let cell = UINib(nibName: "FilterCollectionCell", bundle: Bundle(for: FilterCollectionCell.self))
self.collectionView.register(cell, forCellWithReuseIdentifier: "FilterCollectionCell")
self.collectionFlowOut.estimatedItemSize = CGSize(width: 1, height: 1)
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.sharedData.offerDetails.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "FilterCollectionCell", for: indexPath) as! FilterCollectionCell
if self.sharedData.offerDetails.count > indexPath.row{
let offerDetail = self.sharedData.offerDetails[indexPath.row]
cell.price.text = offerDetail.currency + " " + offerDetail.lowestFare.withCommas()
if let firstSector = offerDetail.flightDetails.first,
let firstOption = firstSector.options.first,
let firstSegment = firstOption.flightSegments.first{
cell.flightName.text = firstSegment.airlineName
let imgURL = self.sharedData.imageURL.replacingOccurrences(of: "{airlineID}", with: firstSegment.airlineCode)
let placeholderImage = UIImage(named: "AirlineIcon")
let url = URL(string: imgURL)
cell.logoImage.kf.indicatorType = .activity
cell.logoImage.kf.setImage(with: url, placeholder: placeholderImage, options: [], progressBlock: nil, completionHandler: nil)
}
}
cell.backgroundColor = UIColor.clear
cell.layoutIfNeeded()
cell.setNeedsLayout()
return cell
}
这是我的collectionView方法
当我删除estimatedItemSize时,滚动效果很好,但我不能根据标签内容调整单元格大小。
self.collectionFlowOut.estimatedItemSize = CGSize(width: 1, height: 1)
答案
只需删除
cell.layoutIfNeeded()
cell.setNeedsLayout()
为什么你这样称呼他们
以上是关于滚动时水平集合视图冻结的主要内容,如果未能解决你的问题,请参考以下文章