gpt4 book ai didi

ios - Collection View beginInteractiveMovementForItem 返回 false

转载 作者:行者123 更新时间:2023-11-28 12:26:55 28 4
gpt4 key购买 nike

我正在使用 Collection View 并希望在用户 Pane 时移动单元格。这是代码。

func longPressPhotoCollectionView(sender: UILongPressGestureRecognizer) {
guard isEditing else {
return
}
let point = sender.location(in: photoCollectionView)
switch sender.state {
case .began:
guard let indexPath = photoCollectionView.indexPathForItem(at: point) else {
return
}
let isS = photoCollectionView.beginInteractiveMovementForItem(at: indexPath)
print(isS)
case .changed:
photoCollectionView.updateInteractiveMovementTargetPosition(point)
case .ended:
photoCollectionView.endInteractiveMovement()
default:
photoCollectionView.cancelInteractiveMovement()
}
}

我怀疑自定义布局会导致此问题。我从 Apple 的文档中找到了这个。

When you call this method, the collection view consults its delegate to make sure the item can be moved. If the data source does not support the movement of the item, this method returns false.

我不知道如何处理动画,尤其是自定义布局。请帮我!谢谢!

最佳答案

在您的 UICollectionViewDataSource 中实现以下内容:

func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {

print("MOVING!")
// Switch the Items in the DataSource
}

关于ios - Collection View beginInteractiveMovementForItem 返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43136378/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com