最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

swift - Collectionview drop animation bug when reordering cells - Stack Overflow

programmeradmin1浏览0评论

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)
    })
}
发布评论

评论列表(0)

  1. 暂无评论