从未在setCollectionViewLayout中调用完成块

时间:2023-01-01 08:09:13

I'm updating the layout of a UICollectionView by moving a cell.

我正在通过移动单元格来更新UICollectionView的布局。

collectionView.moveItem(at: sourceIndex, to: destIndex)

collectionView.collectionViewLayout.invalidateLayout()

collectionView.setCollectionViewLayout(collectionView.collectionViewLayout, animated: true)
{ (done) in
      print("i'm here")
}

But the completion block of setCollectionViewLayout is never called, while the animation is correctly done. Any idea ?

但是从未调用setCollectionViewLayout的完成块,而动画正确完成。任何的想法 ?

Thank you

1 个解决方案

#1


0  

Edit:

BallpointBen is correct - the structure change is not needed.

BallpointBen是正确的 - 不需要改变结构。

I believe the reason you do not get the completion block is because you are setting the New layout to the Existing layout. So, because there is no actual change, there is no "completion".

我相信你没有得到完成块的原因是因为你将New layout设置为Existing布局。所以,因为没有实际的变化,所以没有“完成”。

Whoops... The structure should probably be:

哎呀...结构应该是:

    collectionView.setCollectionViewLayout(collectionView.collectionViewLayout, 
        animated: true, completion: {
            (done) in
            print("I'm here")
    })

#1


0  

Edit:

BallpointBen is correct - the structure change is not needed.

BallpointBen是正确的 - 不需要改变结构。

I believe the reason you do not get the completion block is because you are setting the New layout to the Existing layout. So, because there is no actual change, there is no "completion".

我相信你没有得到完成块的原因是因为你将New layout设置为Existing布局。所以,因为没有实际的变化,所以没有“完成”。

Whoops... The structure should probably be:

哎呀...结构应该是:

    collectionView.setCollectionViewLayout(collectionView.collectionViewLayout, 
        animated: true, completion: {
            (done) in
            print("I'm here")
    })