admin管理员组

文章数量:1318572

I'm having trouble implementing a smooth drop animation when reordering cells in my UICollectionView.

Currently, when I drop an item into a new position, the original cell at sourceIndexPath briefly appears as the moved cell for about half a second before updating correctly.

I tried to remove coordinator, put it before the batch update, after the batch update and also in the completion block. Nothing resolves the problem Screenshot of the bug

    func collectionView(_ collectionView: UICollectionView, performDropWith coordinator: any UICollectionViewDropCoordinator) {
    guard let item = coordinator.items.first,
          let sourceIndexPath = item.sourceIndexPath,
          let destinationIndexPath = coordinator.destinationIndexPath
    else { return }
    let url = FSM.pinnedURLs[sourceIndexPath.item]
    collectionView.performBatchUpdates({
        FSM.movePinnedURL(url: url, position: sourceIndexPath.item, newPosition: destinationIndexPath.item)
        collectionView.deleteItems(at: [sourceIndexPath])
        collectionView.insertItems(at: [destinationIndexPath])
    }, completion: {_ in
        coordinator.drop(item.dragItem, toItemAt: destinationIndexPath)
    })
}

本文标签: swiftCollectionview drop animation bug when reordering cellsStack Overflow