繁体   English   中英

UI-问题,同时对全角和动态高度单元格的UICollectionView进行重新排序

[英]UI-Issues while reordering UICollectionView with full-width and dynamic height cells

我有一个CollectionView,其单元格具有全角和动态(自动布局计算)高度。

我通过设置估计高度来做到这一点:

flowLayout.estimatedItemSize = CGSize(width: 200, height: 10)

然后在委托方法中返回完整宽度和任意高度。

public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    return CGSize(width: collectionView.bounds.width, height: 10)
}

然后在单元格中执行以下操作:

override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
    setNeedsLayout()
    layoutIfNeeded()
    let size = self.systemLayoutSizeFitting(layoutAttributes.size)

    var newFrame = layoutAttributes.frame
    // note: don't change the width
    newFrame.size.height = ceil(size.height)
    layoutAttributes.frame = newFrame

    return layoutAttributes
}

一切都按预期进行...像元一样大小! 大!

现在,我想添加重新排序...我添加了一个GestureRecognizer并使它重新排列我的单元格。

@objc func handleLongPress(gestureRecognizer: UILongPressGestureRecognizer) {

    guard let view = gestureRecognizer.view else { return }
    let location = gestureRecognizer.location(in: view)

    switch gestureRecognizer.state {
    case .began:
        guard let selectedIndexPath = collectionView.indexPathForItem(at: location) else { break }
        collectionView.beginInteractiveMovementForItem(at: selectedIndexPath)
    case .changed:
        collectionView.updateInteractiveMovementTargetPosition(location)
    case .ended:
        collectionView.endInteractiveMovement()
    default:
        collectionView.cancelInteractiveMovement()
    }
}

这基本上也可以工作...但是在重新排序期间,我的单元格产生了奇怪的动画效果...单元格有时会将其大小减小到我的10,但是不允许单元格自行测量。 放开阻力后,它又可以工作了...

我注意到,当我缓存CollectionViewCells的高度时,它会好一些,但是对于我之前从未见过的所有单元格,它将再次是10点高的单元格。

为了使单元格大小正确,我缺少什么?

样品

我也有一个示例项目,此问题可以在这里找到: https : //www.dropbox.com/s/ya6zald4wa6kg10/CollectionViewTester.zip?dl=0

问题是,当对自动调整大小的单元格重新排序时,单元格的大小更改为estimatedItemSize

有报道一个开放的雷达这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM