集合视图 beginInteractiveMovementForItem returns false
Collection view beginInteractiveMovementForItem returns false
我正在使用集合视图并希望在用户窗格时移动单元格。这是代码。
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
}
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.
Apple 文档具有误导性。这似乎暗示您应该覆盖 UICollectionViewDelegate
上的某些方法以使单元格可移动。其实就是一个UICollectionViewDataSource的方法:
optional func collectionView(_ collectionView: UICollectionView,
canMoveItemAt indexPath: IndexPath) -> Bool
https://developer.apple.com/documentation/uikit/uicollectionviewdatasource/1618015-collectionview
我正在使用集合视图并希望在用户窗格时移动单元格。这是代码。
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
}
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.
Apple 文档具有误导性。这似乎暗示您应该覆盖 UICollectionViewDelegate
上的某些方法以使单元格可移动。其实就是一个UICollectionViewDataSource的方法:
optional func collectionView(_ collectionView: UICollectionView,
canMoveItemAt indexPath: IndexPath) -> Bool
https://developer.apple.com/documentation/uikit/uicollectionviewdatasource/1618015-collectionview