我正在使用iOS 11拖放API进行重新排序,并想删除开始拖动时出现的半透明单元格。可能吗?对于拖动,我仅使用UICollectionViewDragDelegate的必需方法:

- (nonnull NSArray<UIDragItem *> *)collectionView:(nonnull UICollectionView *)collectionView
                     itemsForBeginningDragSession:(nonnull id<UIDragSession>)session
                                      atIndexPath:(nonnull NSIndexPath *)indexPath {
    NSItemProvider *itemProvider = [NSItemProvider new];
    UIDragItem *dragItem = [[UIDragItem alloc] initWithItemProvider:itemProvider];

    return @[dragItem];
}

ios - UICollectionView拖放删除半透明单元格-LMLPHP

最佳答案

您可以通过覆盖dragStateDidChange(_ dragState: UICollectionViewCell.DragState)在拖放生命周期中自定义单元格

class MyCell: UICollectionViewCell {

    //...
    override func dragStateDidChange(_ dragState: UICollectionViewCell.DragState) {

        switch dragState {
        case .none:
            self.layer.opacity = 1
        case .lifting:
            return
        case .dragging:
            self.layer.opacity = 0

        }
    }
}

08-06 13:43